Skip to content

Commit 8071d27

Browse files
authored
[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: #66620
1 parent bfc331e commit 8071d27

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

clang/include/clang/AST/APValue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class APValue {
143143
AddrLabelDiff
144144
};
145145

146-
class LValueBase {
146+
class alignas(uint64_t) LValueBase {
147147
typedef llvm::PointerUnion<const ValueDecl *, const Expr *, TypeInfoLValue,
148148
DynamicAllocLValue>
149149
PtrTy;

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ class CodeGenFunction : public CodeGenTypeCache {
725725
};
726726

727727
/// Header for data within LifetimeExtendedCleanupStack.
728-
struct LifetimeExtendedCleanupHeader {
728+
struct alignas(uint64_t) LifetimeExtendedCleanupHeader {
729729
/// The size of the following cleanup object.
730730
unsigned Size;
731731
/// The kind of cleanup to push.
@@ -947,7 +947,8 @@ class CodeGenFunction : public CodeGenTypeCache {
947947
LifetimeExtendedCleanupStack.size() + sizeof(Header) + Header.Size +
948948
(Header.IsConditional ? sizeof(ActiveFlag) : 0));
949949

950-
static_assert(sizeof(Header) % alignof(T) == 0,
950+
static_assert((alignof(LifetimeExtendedCleanupHeader) == alignof(T)) &&
951+
(alignof(T) == alignof(RawAddress)),
951952
"Cleanup will be allocated on misaligned address");
952953
char *Buffer = &LifetimeExtendedCleanupStack[OldSize];
953954
new (Buffer) LifetimeExtendedCleanupHeader(Header);

clang/lib/CodeGen/EHScopeStack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class EHScopeStack {
143143
///
144144
/// Cleanup implementations should generally be declared in an
145145
/// anonymous namespace.
146-
class Cleanup {
146+
class alignas(uint64_t) Cleanup {
147147
// Anchor the construction vtable.
148148
virtual void anchor();
149149

0 commit comments

Comments
 (0)