summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2019-06-14 17:46:38 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2019-06-14 17:46:38 +0000
commit27252a1f9546ba379b76176d6f6707a1ae8d05cd (patch)
tree154bfc319ec7f544da295c4863cb9cb16807c7e1 /clang/test
parent24cdcadcc5e875b05bbb70eb123ea4f0a018ee83 (diff)
downloadbcm5719-llvm-27252a1f9546ba379b76176d6f6707a1ae8d05cd.tar.gz
bcm5719-llvm-27252a1f9546ba379b76176d6f6707a1ae8d05cd.zip
PR23833, DR2140: an lvalue-to-rvalue conversion on a glvalue of type
nullptr_t does not access memory. We now reuse CK_NullToPointer to represent a conversion from a glvalue of type nullptr_t to a prvalue of nullptr_t where necessary. This reinstates r363337, reverted in r363352. llvm-svn: 363429
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Analysis/nullptr.cpp12
-rw-r--r--clang/test/CXX/drs/dr21xx.cpp10
-rw-r--r--clang/test/CodeGenCXX/nullptr.cpp47
3 files changed, 59 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 83c59d01202..7f76440de2e 100644
--- a/clang/test/CXX/drs/dr21xx.cpp
+++ b/clang/test/CXX/drs/dr21xx.cpp
@@ -32,6 +32,16 @@ namespace dr2120 { // dr2120: 7
static_assert(!__is_standard_layout(E), "");
}
+namespace dr2140 { // dr2140: 9
+#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 dr2170 { // dr2170: 9
#if __cplusplus >= 201103L
void f() {
diff --git a/clang/test/CodeGenCXX/nullptr.cpp b/clang/test/CodeGenCXX/nullptr.cpp
index e93f7061bdd..823c0d7d18a 100644
--- a/clang/test/CodeGenCXX/nullptr.cpp
+++ b/clang/test/CodeGenCXX/nullptr.cpp
@@ -22,3 +22,50 @@ 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;
+}
+
+namespace PR39528 {
+ constexpr nullptr_t null = nullptr;
+ void f(nullptr_t);
+ void g() { f(null); }
+}
OpenPOWER on IntegriCloud