-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[Clang] Fix a crash when diagnosing a non relocatable with no copy ctr #143350
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
If lookup did not find a copy constructor, it would return nulll, leading to an assert in `cast`. Fixes llvm#143325
@llvm/pr-subscribers-clang Author: Corentin Jabot (cor3ntin) ChangesIf lookup did not find a copy constructor, it would return nulll, leading to an assert in Fixes #143325 Full diff: https://github.com/llvm/llvm-project/pull/143350.diff 2 Files Affected:
diff --git a/clang/lib/Sema/SemaTypeTraits.cpp b/clang/lib/Sema/SemaTypeTraits.cpp
index 330f2aa750a09..a2cef76cfc673 100644
--- a/clang/lib/Sema/SemaTypeTraits.cpp
+++ b/clang/lib/Sema/SemaTypeTraits.cpp
@@ -2052,7 +2052,7 @@ static void DiagnoseNonTriviallyRelocatableReason(Sema &SemaRef,
}
if (!D->hasSimpleMoveConstructor() && !D->hasSimpleCopyConstructor()) {
- const auto *Decl = cast<CXXConstructorDecl>(
+ const auto *Decl = cast_or_null<CXXConstructorDecl>(
LookupSpecialMemberFromXValue(SemaRef, D, /*Assign=*/false));
if (Decl && Decl->isUserProvided())
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
diff --git a/clang/test/SemaCXX/type-traits-unsatisfied-diags.cpp b/clang/test/SemaCXX/type-traits-unsatisfied-diags.cpp
index 0256569fcca5f..26378ef25ee99 100644
--- a/clang/test/SemaCXX/type-traits-unsatisfied-diags.cpp
+++ b/clang/test/SemaCXX/type-traits-unsatisfied-diags.cpp
@@ -145,6 +145,50 @@ static_assert(__builtin_is_cpp_trivially_relocatable(U2));
}
+
+namespace GH143325 {
+struct Foo { // expected-note {{previous definition is here}}
+ Foo(const Foo&);
+ ~Foo();
+};
+
+struct Foo { // expected-error {{redefinition of 'Foo'}}
+ Foo();
+ int;
+};
+struct Wrapper { // #GH143325-Wrapper
+ union {
+ Foo p;
+ } u;
+};
+
+static_assert(__builtin_is_cpp_trivially_relocatable(Wrapper));
+// expected-error@-1 {{static assertion failed due to requirement '__builtin_is_cpp_trivially_relocatable(GH143325::Wrapper)'}} \
+// expected-note@-1 {{'Wrapper' is not trivially relocatable}} \
+// expected-note@-1 {{because it has a non-trivially-relocatable member 'u' of type 'union}} \
+// expected-note@-1 {{because it has a deleted destructor}}
+// expected-note@#GH143325-Wrapper {{'Wrapper' defined here}}
+
+struct Polymorphic {
+ virtual ~Polymorphic();
+};
+
+struct UnionOfPolymorphic { // #GH143325-UnionOfPolymorphic
+ union {
+ Polymorphic p;
+ int i;
+ } u;
+};
+
+static_assert(__builtin_is_cpp_trivially_relocatable(UnionOfPolymorphic));
+// expected-error@-1 {{static assertion failed due to requirement '__builtin_is_cpp_trivially_relocatable(GH143325::UnionOfPolymorphic)'}} \
+// expected-note@-1 {{'UnionOfPolymorphic' is not trivially relocatable}} \
+// expected-note@-1 {{because it has a non-trivially-relocatable member 'u' of type 'union}} \
+// expected-note@-1 {{because it has a deleted destructor}} \
+// expected-note@#GH143325-UnionOfPolymorphic {{'UnionOfPolymorphic' defined here}}
+
+}
+
namespace trivially_copyable {
struct B {
virtual ~B();
|
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.
Looks good
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/162/builds/24122 Here is the relevant piece of the build log for the reference
|
llvm#143350) If lookup did not find a copy constructor, it would return nulll, leading to an assert in `cast`. Fixes llvm#143325
llvm#143350) If lookup did not find a copy constructor, it would return nulll, leading to an assert in `cast`. Fixes llvm#143325
llvm#143350) If lookup did not find a copy constructor, it would return nulll, leading to an assert in `cast`. Fixes llvm#143325
If lookup did not find a copy constructor, it would return nulll, leading to an assert in
cast
.Fixes #143325