1 // RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -I%S -emit-llvm -o - %s | FileCheck %s
2 
3 #include <typeinfo>
4 
5 // CHECK: @_ZTIDn = external constant i8*
6 int* a = nullptr;
7 
f()8 void f() {
9   int* a = nullptr;
10 }
11 
12 typedef decltype(nullptr) nullptr_t;
13 
14 nullptr_t get_nullptr();
15 
16 struct X { };
g()17 void g() {
18   // CHECK: call i8* @_Z11get_nullptrv()
19   int (X::*pmf)(int) = get_nullptr();
20 }
21 
f2()22 const std::type_info& f2() {
23   return typeid(nullptr_t);
24 }
25 
26 union U {
27   int n;
28   nullptr_t b;
29 };
30 // CHECK-LABEL: define {{.*}}pr23833_a
31 // CHECK: store
32 // CHECK: load
33 // CHECK-NOT: load
34 // CHECK: ret i1 false
pr23833_a(U & u)35 bool pr23833_a(U &u) { return bool(u.b); }
36 
37 // CHECK-LABEL: define {{.*}}pr23833_b
38 // CHECK: store
39 // CHECK: load
40 // CHECK-NOT: load
41 // CHECK: ret i8* null
pr23833_b(nullptr_t & n)42 nullptr_t pr23833_b(nullptr_t &n) { return n; }
43 
44 struct X1 { operator int*(); };
45 struct X2 { operator const nullptr_t&(); };
46 
47 // CHECK-LABEL: define {{.*}}pr23833_c
48 // CHECK: call {{.*}}X1
49 // CHECK: call {{.*}}X2
50 // CHECK-NOT: load
51 // CHECK: ret i32
pr23833_c()52 int pr23833_c() {
53   return X1() != X2();
54 }
55 
56 // CHECK-LABEL: define {{.*}}pr23833_d
57 // CHECK: call {{.*}}X2
58 // CHECK-NOT: load
59 // CHECK: store
60 // CHECK: load
61 // CHECK: ret i32*
pr23833_d()62 int *pr23833_d() {
63   int *p = X2();
64   return p;
65 }
66 
67 namespace PR39528 {
68   constexpr nullptr_t null = nullptr;
69   void f(nullptr_t);
g()70   void g() { f(null); }
71 }
72