-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[WIP] [clang] Align cleanup structs to prevent SIGBUS on sparc32 #152866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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: llvm#66620
@llvm/pr-subscribers-clang Author: Koakuma (koachan) ChangesThe 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 Full diff: https://github.com/llvm/llvm-project/pull/152866.diff 3 Files Affected:
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<const ValueDecl *, const Expr *, TypeInfoLValue,
DynamicAllocLValue>
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();
|
@llvm/pr-subscribers-clang-codegen Author: Koakuma (koachan) ChangesThe 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 Full diff: https://github.com/llvm/llvm-project/pull/152866.diff 3 Files Affected:
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<const ValueDecl *, const Expr *, TypeInfoLValue,
DynamicAllocLValue>
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();
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I've run a However, when trying an
Besides, I think it would be clearer to use |
Changed to this, it should fix the i386 issue. |
It did indeed as confirmed by a 2-stage |
I've now successfully completed the Solaris/sparc test for good measure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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