From f8c567f182c8b40a2323d6d700e11e5e95e229ca Mon Sep 17 00:00:00 2001 From: Koakuma Date: Sat, 9 Aug 2025 23:34:40 +0700 Subject: [PATCH 1/2] [clang] Align cleanup structs to prevent SIGBUS on sparc32 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 --- clang/include/clang/AST/APValue.h | 2 +- clang/lib/CodeGen/CodeGenFunction.h | 5 +++-- clang/lib/CodeGen/EHScopeStack.h | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/AST/APValue.h b/clang/include/clang/AST/APValue.h index 9999a30c51ade..167fa7078d028 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(8) LValueBase { typedef llvm::PointerUnion PtrTy; diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index bf16d727bac04..393c5161177df 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(8) 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..1a9cff48ad852 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(8) Cleanup { // Anchor the construction vtable. virtual void anchor(); From 80a9f44cc3c1ab24bbc7c9abb5a72ccdf71bca00 Mon Sep 17 00:00:00 2001 From: Koakuma Date: Tue, 12 Aug 2025 22:13:44 +0700 Subject: [PATCH 2/2] Use alignas(uint64_t) --- clang/include/clang/AST/APValue.h | 2 +- clang/lib/CodeGen/CodeGenFunction.h | 2 +- clang/lib/CodeGen/EHScopeStack.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/AST/APValue.h b/clang/include/clang/AST/APValue.h index 167fa7078d028..cb942ea865e2d 100644 --- a/clang/include/clang/AST/APValue.h +++ b/clang/include/clang/AST/APValue.h @@ -143,7 +143,7 @@ class APValue { AddrLabelDiff }; - class alignas(8) LValueBase { + class alignas(uint64_t) LValueBase { typedef llvm::PointerUnion PtrTy; diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 393c5161177df..574b02878cb19 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 alignas(8) LifetimeExtendedCleanupHeader { + struct alignas(uint64_t) LifetimeExtendedCleanupHeader { /// The size of the following cleanup object. unsigned Size; /// The kind of cleanup to push. diff --git a/clang/lib/CodeGen/EHScopeStack.h b/clang/lib/CodeGen/EHScopeStack.h index 1a9cff48ad852..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 alignas(8) Cleanup { + class alignas(uint64_t) Cleanup { // Anchor the construction vtable. virtual void anchor();