-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clang] Add some CodeGen tests for CWG 2xx issues #80823
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
Changes from all commits
560713b
f7a0d28
d9ee822
4c8e542
964b9df
7147c04
323d41e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK | ||
// RUN: %clang_cc1 -std=c++11 %s -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK | ||
// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK | ||
// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK | ||
// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK | ||
// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK | ||
// RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK | ||
|
||
#if __cplusplus == 199711L | ||
#define NOTHROW throw() | ||
#else | ||
#define NOTHROW noexcept(true) | ||
#endif | ||
|
||
namespace dr201 { // dr201: 2.8 | ||
|
||
extern void full_expr_fence() NOTHROW; | ||
|
||
struct A { | ||
~A() NOTHROW {} | ||
}; | ||
|
||
struct B { | ||
B(A) NOTHROW {} | ||
~B() NOTHROW {} | ||
}; | ||
|
||
void foo() { | ||
full_expr_fence(); | ||
B b = A(); | ||
full_expr_fence(); | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}} void @dr201::foo() | ||
// CHECK: call void @dr201::full_expr_fence() | ||
// CHECK: call void @dr201::B::B(dr201::A) | ||
// CHECK: call void @dr201::A::~A() | ||
// CHECK: call void @dr201::full_expr_fence() | ||
// CHECK: call void @dr201::B::~B() | ||
// CHECK-LABEL: } | ||
|
||
} // namespace dr201 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK | ||
// RUN: %clang_cc1 -std=c++11 %s -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK | ||
// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK | ||
// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK | ||
// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK | ||
// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK | ||
// RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK | ||
|
||
#if __cplusplus == 199711L | ||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Wvariadic-macros" | ||
#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__) | ||
#pragma clang diagnostic pop | ||
#endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wowzers, lot of work to make this happen, but thank you for doing it! |
||
|
||
namespace dr210 { // dr210: 2.7 | ||
struct B { | ||
long i; | ||
B(); | ||
virtual ~B(); | ||
}; | ||
|
||
static_assert(sizeof(B) == 16, ""); | ||
|
||
struct D : B { | ||
long j; | ||
D(); | ||
}; | ||
|
||
static_assert(sizeof(D) == 24, ""); | ||
|
||
void toss(const B* b) { | ||
throw *b; | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}} void @dr210::toss(dr210::B const*) | ||
// CHECK: %[[EXCEPTION:.*]] = call ptr @__cxa_allocate_exception(i64 16) | ||
// CHECK: call void @__cxa_throw(ptr %[[EXCEPTION]], ptr @typeinfo for dr210::B, ptr @dr210::B::~B()) | ||
// CHECK-LABEL: } | ||
|
||
} // namespace dr210 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK | ||
// RUN: %clang_cc1 -std=c++11 %s -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK | ||
// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK | ||
// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK | ||
// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK | ||
// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK | ||
// RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes -o - -fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s --check-prefixes CHECK | ||
|
||
namespace dr292 { // dr292: 2.9 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think an additional test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated PR description to mention that resolution to 292 has been superseded by P0145R3. The latter is the wording I'm testing: we're making sure that we pass to deallocation function what was returned by allocation function, and making sure that potentially-throwing expression is evaluated in-between. In |
||
|
||
extern int g(); | ||
|
||
struct A { | ||
A(int) throw() {} | ||
}; | ||
|
||
void f() { | ||
new A(g()); | ||
} | ||
|
||
// CHECK-LABEL: define {{.*}} void @dr292::f()() | ||
// CHECK: %[[CALL:.+]] = call {{.*}} @operator new(unsigned long)({{.*}}) | ||
// CHECK: invoke {{.*}} i32 @dr292::g()() | ||
// CHECK-NEXT: to {{.*}} unwind label %lpad | ||
// CHECK-LABEL: lpad: | ||
// CHECK: call void @operator delete(void*)(ptr {{.*}} %[[CALL]]) | ||
// CHECK-LABEL: eh.resume: | ||
// CHECK-LABEL: } | ||
|
||
} // namespace dr292 |
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.
What is tested here?
My understanding is that this issue deal with the sequence of destructions in
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.
I'll update the test to make it more clear, but I test whether a temporary is destroyed at the end of full expression. Which I believe is what 201 is about, contrary to its title.
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.
TBH, I think this is one of those "textual pendentry" type DRs where two sentences were inconsistent. It is complaining that in the expression:
B b = A();
whether the call toB::B
is 'part' of the full expression (so the deletion of the temporary isn't really meaningful).It was never contentous based on my reading whether the temporary was deleted 'end of statement' (in fact, it was, in 1 sentence deleted AFTER init, which was AFTER end of statement, but that wasn't the case in the other sentence).
Because of this, I think your test is reasonably fine, except I'd add a check for the call to
B::B
beforeA::~A
.Also, it might be valuable to get the 'default argument to a default constructor called in array' is deleted BEFORE the initialization of the array.
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.
I added check for
B::B()
.I also added a test for related CWG124 to #80338