Skip to content

Commit 080a2f8

Browse files
koachantru
authored andcommitted
[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 (cherry picked from commit 8071d27)
1 parent 29b3836 commit 080a2f8

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
@@ -727,7 +727,7 @@ class CodeGenFunction : public CodeGenTypeCache {
727727
};
728728

729729
/// Header for data within LifetimeExtendedCleanupStack.
730-
struct LifetimeExtendedCleanupHeader {
730+
struct alignas(uint64_t) LifetimeExtendedCleanupHeader {
731731
/// The size of the following cleanup object.
732732
unsigned Size;
733733
/// The kind of cleanup to push.
@@ -949,7 +949,8 @@ class CodeGenFunction : public CodeGenTypeCache {
949949
LifetimeExtendedCleanupStack.size() + sizeof(Header) + Header.Size +
950950
(Header.IsConditional ? sizeof(ActiveFlag) : 0));
951951

952-
static_assert(sizeof(Header) % alignof(T) == 0,
952+
static_assert((alignof(LifetimeExtendedCleanupHeader) == alignof(T)) &&
953+
(alignof(T) == alignof(RawAddress)),
953954
"Cleanup will be allocated on misaligned address");
954955
char *Buffer = &LifetimeExtendedCleanupStack[OldSize];
955956
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)