[clang] 88324f1 - [clang][bytecode][NFC] Simplify align_up/down implementation (#160880)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 26 08:26:42 PDT 2025
Author: Timm Baeder
Date: 2025-09-26T17:26:38+02:00
New Revision: 88324f1cabc89c841df6928bd1c79b1604194b22
URL: https://github.com/llvm/llvm-project/commit/88324f1cabc89c841df6928bd1c79b1604194b22
DIFF: https://github.com/llvm/llvm-project/commit/88324f1cabc89c841df6928bd1c79b1604194b22.diff
LOG: [clang][bytecode][NFC] Simplify align_up/down implementation (#160880)
Fix a double assignment to a local variable and use the new
popToAPSInt() overload.
Added:
Modified:
clang/lib/AST/ByteCode/InterpBuiltin.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 9076946d29657..6c946e3cc2f21 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1169,8 +1169,7 @@ static bool interp__builtin_is_aligned_up_down(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const CallExpr *Call,
unsigned BuiltinOp) {
- PrimType AlignmentT = *S.Ctx.classify(Call->getArg(1));
- const APSInt &Alignment = popToAPSInt(S.Stk, AlignmentT);
+ const APSInt &Alignment = popToAPSInt(S, Call->getArg(1));
if (Alignment < 0 || !Alignment.isPowerOf2()) {
S.FFDiag(Call, diag::note_constexpr_invalid_alignment) << Alignment;
@@ -1184,8 +1183,7 @@ static bool interp__builtin_is_aligned_up_down(InterpState &S, CodePtr OpPC,
return false;
}
- // The first parameter is either an integer or a pointer (but not a function
- // pointer).
+ // The first parameter is either an integer or a pointer.
PrimType FirstArgT = *S.Ctx.classify(Call->getArg(0));
if (isIntegralType(FirstArgT)) {
@@ -1204,12 +1202,12 @@ static bool interp__builtin_is_aligned_up_down(InterpState &S, CodePtr OpPC,
}
return true;
}
-
assert(FirstArgT == PT_Ptr);
const Pointer &Ptr = S.Stk.pop<Pointer>();
+ if (!Ptr.isBlockPointer())
+ return false;
- unsigned PtrOffset = Ptr.getByteOffset();
- PtrOffset = Ptr.getIndex();
+ unsigned PtrOffset = Ptr.getIndex();
CharUnits BaseAlignment =
S.getASTContext().getDeclAlign(Ptr.getDeclDesc()->asValueDecl());
CharUnits PtrAlign =
More information about the cfe-commits
mailing list