1 // RUN: %clang_cc1 -S %s -std=c2x -emit-llvm -o - | FileCheck %s
3 // Test that null <-> nullptr_t conversions work as expected.
4 typedef typeof(nullptr) nullptr_t
;
6 nullptr_t nullptr_t_val
;
9 void nullptr_func(nullptr_t
);
12 // Test initialization
13 bool bool_from_nullptr_t
= nullptr_t_val
;
14 nullptr_t nullptr_t_from_nullptr
= nullptr;
15 void *vp_from_nullptr_t
= nullptr_t_val
;
16 nullptr_t nullptr_t_from_vp
= (void *)0;
17 nullptr_t nullptr_t_from_int
= 0;
20 bool_from_nullptr_t
= nullptr_t_val
;
21 nullptr_t_from_nullptr
= nullptr;
22 vp_from_nullptr_t
= nullptr_t_val
;
23 nullptr_t_from_vp
= (void *)0;
24 nullptr_t_from_int
= 0;
27 bool_func(nullptr_t_from_nullptr
);
28 nullptr_func(nullptr_t_from_nullptr
);
30 nullptr_func((void *)0);
31 nullptr_func(nullptr);
34 // Allocation of locals
35 // CHECK: %[[bool_from_nullptr_t:.*]] = alloca i8
36 // CHECK: %[[nullptr_t_from_nullptr:.*]] = alloca ptr
37 // CHECK: %[[vp_from_nullptr_t:.*]] = alloca ptr
38 // CHECK: %[[nullptr_t_from_vp:.*]] = alloca ptr
39 // CHECK: %[[nullptr_t_from_int:.*]] = alloca ptr
41 // Initialization of locals
42 // CHECK: store i8 0, ptr %[[bool_from_nullptr_t]]
43 // CHECK: store ptr null, ptr %[[nullptr_t_from_nullptr]]
44 // CHECK: store ptr null, ptr %[[vp_from_nullptr_t]]
45 // CHECK: store ptr null, ptr %[[nullptr_t_from_vp]]
46 // CHECK: store ptr null, ptr %[[nullptr_t_from_int]]
48 // Assignment expressions
49 // CHECK: store i8 0, ptr %[[bool_from_nullptr_t]]
50 // CHECK: store ptr null, ptr %[[nullptr_t_from_nullptr]]
51 // CHECK: store ptr null, ptr %[[vp_from_nullptr_t]]
52 // CHECK: store ptr null, ptr %[[nullptr_t_from_vp]]
53 // CHECK: store ptr null, ptr %[[nullptr_t_from_int]]
56 // CHECK: call void @bool_func(i1 noundef {{(zeroext )?}}false)
57 // CHECK: call void @nullptr_func(ptr null)
58 // CHECK: call void @nullptr_func(ptr null)
59 // CHECK: call void @nullptr_func(ptr null)
60 // CHECK: call void @nullptr_func(ptr null)
61 // CHECK: call void @nullptr_func(ptr null)