diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Analysis/nullptr.cpp | 12 | ||||
-rw-r--r-- | clang/test/CXX/drs/dr21xx.cpp | 10 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/nullptr.cpp | 41 |
3 files changed, 53 insertions, 10 deletions
diff --git a/clang/test/Analysis/nullptr.cpp b/clang/test/Analysis/nullptr.cpp index 38e099b7fbd..e9b975c148a 100644 --- a/clang/test/Analysis/nullptr.cpp +++ b/clang/test/Analysis/nullptr.cpp @@ -128,18 +128,10 @@ void shouldNotCrash() { decltype(nullptr) p; // expected-note{{'p' declared without an initial value}} if (getSymbol()) // expected-note {{Assuming the condition is false}} // expected-note@-1{{Taking false branch}} - // expected-note@-2{{Assuming the condition is false}} - // expected-note@-3{{Taking false branch}} - // expected-note@-4{{Assuming the condition is true}} - // expected-note@-5{{Taking true branch}} - invokeF(p); // expected-warning{{1st function call argument is an uninitialized value}} - // expected-note@-1{{1st function call argument is an uninitialized value}} - if (getSymbol()) // expected-note {{Assuming the condition is false}} - // expected-note@-1{{Taking false branch}} // expected-note@-2{{Assuming the condition is true}} // expected-note@-3{{Taking true branch}} - invokeF(nullptr); // expected-note {{Calling 'invokeF'}} - // expected-note@-1{{Passing null pointer value via 1st parameter 'x'}} + invokeF(p); // expected-note {{Calling 'invokeF'}} + // expected-note@-1{{Passing null pointer value via 1st parameter 'x'}} if (getSymbol()) { // expected-note {{Assuming the condition is true}} // expected-note@-1{{Taking true branch}} X *xx = Type().x; // expected-note {{Null pointer value stored to field 'x'}} diff --git a/clang/test/CXX/drs/dr21xx.cpp b/clang/test/CXX/drs/dr21xx.cpp index 2522ff7dbde..b111529b09f 100644 --- a/clang/test/CXX/drs/dr21xx.cpp +++ b/clang/test/CXX/drs/dr21xx.cpp @@ -19,6 +19,16 @@ namespace dr2120 { // dr2120: 7 static_assert(!__is_standard_layout(E), ""); } +namespace dr2140 { // dr2140: 8 +#if __cplusplus >= 201103L + union U { int a; decltype(nullptr) b; }; + constexpr int *test(U u) { + return u.b; + } + static_assert(!test({123}), "u.b should be valid even when b is inactive"); +#endif +} + namespace dr2180 { // dr2180: yes class A { A &operator=(const A &); // expected-note 0-2{{here}} diff --git a/clang/test/CodeGenCXX/nullptr.cpp b/clang/test/CodeGenCXX/nullptr.cpp index e93f7061bdd..222e5e5803c 100644 --- a/clang/test/CodeGenCXX/nullptr.cpp +++ b/clang/test/CodeGenCXX/nullptr.cpp @@ -22,3 +22,44 @@ void g() { const std::type_info& f2() { return typeid(nullptr_t); } + +union U { + int n; + nullptr_t b; +}; +// CHECK-LABEL: define {{.*}}pr23833_a +// CHECK: store +// CHECK: load +// CHECK-NOT: load +// CHECK: ret i1 false +bool pr23833_a(U &u) { return u.b; } + +// CHECK-LABEL: define {{.*}}pr23833_b +// CHECK: store +// CHECK: load +// CHECK-NOT: load +// CHECK: ret i8* null +nullptr_t pr23833_b(nullptr_t &n) { return n; } + +struct X1 { operator int*(); }; +struct X2 { operator const nullptr_t&(); }; + +// CHECK-LABEL: define {{.*}}pr23833_c +// CHECK: call {{.*}}X1 +// CHECK: call {{.*}}X2 +// CHECK-NOT: load +// CHECK: ret i32 +int pr23833_c() { + return X1() != X2(); +} + +// CHECK-LABEL: define {{.*}}pr23833_d +// CHECK: call {{.*}}X2 +// CHECK-NOT: load +// CHECK: store +// CHECK: load +// CHECK: ret i32* +int *pr23833_d() { + int *p = X2(); + return p; +} |