Author: Timm Baeder
Date: 2026-10-15T11:06:29+02:00
New Revision: a39eb142e6505a781a14bb7828e49cb8ec6660b6

URL: 
https://github.com/llvm/llvm-project/commit/a39eb142e6505a781a14bb7828e49cb8ec6660b6
DIFF: 
https://github.com/llvm/llvm-project/commit/a39eb142e6505a781a14bb7828e49cb8ec6660b6.diff

LOG: [clang][bytecode][NFC] Refactor `alignOfType` (#232193)

Fix capitalization, define `AlignOfReturnsPreferred` only once it's
needed and fix the parameter name comment for `getDeclAlign()`.

The latter is also done in `ExprConstant.cpp`.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Compiler.cpp
    clang/lib/AST/ExprConstant.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 1875eade83673..40b36b4e715a1 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -2813,11 +2813,8 @@ bool Compiler<Emitter>::VisitEmbedExpr(const EmbedExpr 
*E) {
   return this->visit(*It);
 }
 
-static CharUnits AlignOfType(QualType T, const ASTContext &ASTCtx,
+static CharUnits alignOfType(QualType T, const ASTContext &ASTCtx,
                              UnaryExprOrTypeTrait Kind) {
-  bool AlignOfReturnsPreferred =
-      ASTCtx.getLangOpts().isCompatibleWith(LangOptions::ClangABI::Ver7);
-
   // C++ [expr.alignof]p3:
   //     When alignof is applied to a reference type, the result is the
   //     alignment of the referenced type.
@@ -2827,6 +2824,8 @@ static CharUnits AlignOfType(QualType T, const ASTContext 
&ASTCtx,
   if (T.getQualifiers().hasUnaligned())
     return CharUnits::One();
 
+  bool AlignOfReturnsPreferred =
+      ASTCtx.getLangOpts().isCompatibleWith(LangOptions::ClangABI::Ver7);
   // __alignof is defined to return the preferred alignment.
   // Before 8, clang returned the preferred alignment for alignof and
   // _Alignof as well.
@@ -2909,7 +2908,7 @@ bool Compiler<Emitter>::VisitUnaryExprOrTypeTraitExpr(
     if (E->isArgumentType()) {
       QualType ArgType = E->getTypeOfArgument();
 
-      Size = AlignOfType(ArgType, ASTCtx, Kind);
+      Size = alignOfType(ArgType, ASTCtx, Kind);
     } else {
       // Argument is an expression, not a type.
       const Expr *Arg = E->getArgumentExpr()->IgnoreParens();
@@ -2925,12 +2924,12 @@ bool Compiler<Emitter>::VisitUnaryExprOrTypeTraitExpr(
       // default to 1 in those cases.
       if (const auto *DRE = dyn_cast<DeclRefExpr>(Arg))
         Size = ASTCtx.getDeclAlign(DRE->getDecl(),
-                                   /*RefAsPointee*/ true);
+                                   /*ForAlignOf=*/true);
       else if (const auto *ME = dyn_cast<MemberExpr>(Arg))
         Size = ASTCtx.getDeclAlign(ME->getMemberDecl(),
-                                   /*RefAsPointee*/ true);
+                                   /*ForAlignOf=*/true);
       else
-        Size = AlignOfType(Arg->getType(), ASTCtx, Kind);
+        Size = alignOfType(Arg->getType(), ASTCtx, Kind);
     }
 
     if (DiscardResult)

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 94e5248526818..6d390032e2c71 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -10625,11 +10625,11 @@ CharUnits GetAlignOfExpr(const ASTContext &Ctx, const 
Expr *E,
   // to 1 in those cases.
   if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
     return Ctx.getDeclAlign(DRE->getDecl(),
-                            /*RefAsPointee*/ true);
+                            /*ForAlignOf=*/true);
 
   if (const MemberExpr *ME = dyn_cast<MemberExpr>(E))
     return Ctx.getDeclAlign(ME->getMemberDecl(),
-                            /*RefAsPointee*/ true);
+                            /*ForAlignOf=*/true);
 
   return GetAlignOfType(Ctx, E->getType(), ExprKind);
 }


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to