Author: Koakuma Date: 2025-08-13T23:26:36+07:00 New Revision: 8071d279fd97134f798699795dfb0b16747ce247
URL: https://github.com/llvm/llvm-project/commit/8071d279fd97134f798699795dfb0b16747ce247 DIFF: https://github.com/llvm/llvm-project/commit/8071d279fd97134f798699795dfb0b16747ce247.diff LOG: [WIP] [clang] Align cleanup structs to prevent SIGBUS on sparc32 (#152866) The cleanup structs expect that pointers and (u)int64_t have the same alignment requirements, which isn't true on sparc32, which causes SIGBUSes. See also: https://github.com/llvm/llvm-project/issues/66620 Added: Modified: clang/include/clang/AST/APValue.h clang/lib/CodeGen/CodeGenFunction.h clang/lib/CodeGen/EHScopeStack.h Removed: ################################################################################ diff --git a/clang/include/clang/AST/APValue.h b/clang/include/clang/AST/APValue.h index 9999a30c51ade..cb942ea865e2d 100644 --- a/clang/include/clang/AST/APValue.h +++ b/clang/include/clang/AST/APValue.h @@ -143,7 +143,7 @@ class APValue { AddrLabelDiff }; - class LValueBase { + class alignas(uint64_t) LValueBase { typedef llvm::PointerUnion<const ValueDecl *, const Expr *, TypeInfoLValue, DynamicAllocLValue> PtrTy; diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 84be42244d39c..ad318f289ee83 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -725,7 +725,7 @@ class CodeGenFunction : public CodeGenTypeCache { }; /// Header for data within LifetimeExtendedCleanupStack. - struct LifetimeExtendedCleanupHeader { + struct alignas(uint64_t) LifetimeExtendedCleanupHeader { /// The size of the following cleanup object. unsigned Size; /// The kind of cleanup to push. @@ -947,7 +947,8 @@ class CodeGenFunction : public CodeGenTypeCache { LifetimeExtendedCleanupStack.size() + sizeof(Header) + Header.Size + (Header.IsConditional ? sizeof(ActiveFlag) : 0)); - static_assert(sizeof(Header) % alignof(T) == 0, + static_assert((alignof(LifetimeExtendedCleanupHeader) == alignof(T)) && + (alignof(T) == alignof(RawAddress)), "Cleanup will be allocated on misaligned address"); char *Buffer = &LifetimeExtendedCleanupStack[OldSize]; new (Buffer) LifetimeExtendedCleanupHeader(Header); diff --git a/clang/lib/CodeGen/EHScopeStack.h b/clang/lib/CodeGen/EHScopeStack.h index ed11dc2bb05d7..54f6ceaa52b95 100644 --- a/clang/lib/CodeGen/EHScopeStack.h +++ b/clang/lib/CodeGen/EHScopeStack.h @@ -143,7 +143,7 @@ class EHScopeStack { /// /// Cleanup implementations should generally be declared in an /// anonymous namespace. - class Cleanup { + class alignas(uint64_t) Cleanup { // Anchor the construction vtable. virtual void anchor(); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits