Debian Codegraph @

clang/test/CIR/CodeGen/nullptr-init.cpp

raw
1 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu %s -fclangir -emit-cir -o %t.cir
2 // RUN: FileCheck --input-file=%t.cir -check-prefix=CIR %s
3 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu %s -fclangir -emit-llvm -o %t-cir.ll
4 // RUN: FileCheck --input-file=%t-cir.ll -check-prefix=LLVM %s
5 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu %s -emit-llvm -o %t.ll
6 // RUN: FileCheck --input-file=%t.ll -check-prefix=OGCG %s
7
8 void t1() {
9 int *p1 = nullptr;
10 int *p2 = 0;
11 int *p3 = (int*)0;
12 }
13
14 // CIR: cir.func{{.*}} @_Z2t1v()
15 // CIR-NEXT: %[[P1:.*]] = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>, ["p1", init] {alignment = 8 : i64}
16 // CIR-NEXT: %[[P2:.*]] = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>, ["p2", init] {alignment = 8 : i64}
17 // CIR-NEXT: %[[P3:.*]] = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>, ["p3", init] {alignment = 8 : i64}
18 // CIR-NEXT: %[[NULLPTR1:.*]] = cir.const #cir.ptr<null> : !cir.ptr<!s32i>
19 // CIR-NEXT: cir.store{{.*}} %[[NULLPTR1]], %[[P1]] : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>
20 // CIR-NEXT: %[[NULLPTR2:.*]] = cir.const #cir.ptr<null> : !cir.ptr<!s32i>
21 // CIR-NEXT: cir.store{{.*}} %[[NULLPTR2]], %[[P2]] : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>
22 // CIR-NEXT: %[[NULLPTR3:.*]] = cir.const #cir.ptr<null> : !cir.ptr<!s32i>
23 // CIR-NEXT: cir.store{{.*}} %[[NULLPTR3]], %[[P3]] : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>
24 // CIR-NEXT: cir.return
25 // CIR-NEXT: }
26
27 // LLVM: define{{.*}} @_Z2t1v()
28 // LLVM-NEXT: %[[P1:.*]] = alloca ptr, i64 1, align 8
29 // LLVM-NEXT: %[[P2:.*]] = alloca ptr, i64 1, align 8
30 // LLVM-NEXT: %[[P3:.*]] = alloca ptr, i64 1, align 8
31 // LLVM-NEXT: store ptr null, ptr %[[P1]], align 8
32 // LLVM-NEXT: store ptr null, ptr %[[P2]], align 8
33 // LLVM-NEXT: store ptr null, ptr %[[P3]], align 8
34 // LLVM-NEXT: ret void
35 // LLVM-NEXT: }
36
37 // OGCG: define{{.*}} @_Z2t1v()
38 // OGCG-NEXT: entry:
39 // OGCG-NEXT: %[[P1:.*]] = alloca ptr, align 8
40 // OGCG-NEXT: %[[P2:.*]] = alloca ptr, align 8
41 // OGCG-NEXT: %[[P3:.*]] = alloca ptr, align 8
42 // OGCG-NEXT: store ptr null, ptr %[[P1]], align 8
43 // OGCG-NEXT: store ptr null, ptr %[[P2]], align 8
44 // OGCG-NEXT: store ptr null, ptr %[[P3]], align 8
45 // OGCG-NEXT: ret void
46 // OGCG-NEXT: }