[clang] [clang][bytecode][NFC] Refactor `alignOfType` (PR #232193)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 14 23:20:19 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/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`.
>From 96005e1f635500ad27eb565dbf9bda7c7302f2ce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Thu, 15 Oct 2026 08:13:01 +0200
Subject: [PATCH] [clang][bytecode][NFC] Refactor `alignOfType`
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`.
---
clang/lib/AST/ByteCode/Compiler.cpp | 15 +++++++--------
clang/lib/AST/ExprConstant.cpp | 4 ++--
2 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 6ba5099a78b877..e65aeeed55146e 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -2805,11 +2805,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.
@@ -2819,6 +2816,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.
@@ -2901,7 +2900,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();
@@ -2917,12 +2916,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 87909992a46d51..e98313a4b52ea6 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);
}
More information about the cfe-commits
mailing list