1 // RUN: %clang_cc1 -triple x86_64 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
3 #define _(x) (__builtin_preserve_access_index(x))
5 const void *unit1(const void *arg
) {
8 // CHECK: define dso_local ptr @unit1
9 // CHECK-NOT: llvm.preserve.array.access.index
10 // CHECK-NOT: llvm.preserve.struct.access.index
11 // CHECK-NOT: llvm.preserve.union.access.index
13 const void *unit2(void) {
14 return _((const void *)0xffffffffFFFF0000ULL
);
16 // CHECK: define dso_local ptr @unit2
17 // CHECK-NOT: llvm.preserve.array.access.index
18 // CHECK-NOT: llvm.preserve.struct.access.index
19 // CHECK-NOT: llvm.preserve.union.access.index
21 const void *unit3(const int *arg
) {
24 // CHECK: define dso_local ptr @unit3
25 // CHECK-NOT: llvm.preserve.array.access.index
26 // CHECK-NOT: llvm.preserve.struct.access.index
27 // CHECK-NOT: llvm.preserve.union.access.index
29 const void *unit4(const int *arg
) {
32 // CHECK: define dso_local ptr @unit4
33 // CHECK-NOT: getelementptr
34 // CHECK: call ptr @llvm.preserve.array.access.index.p0.p0(ptr elementtype(i32) %{{[0-9a-z]+}}, i32 0, i32 1), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[POINTER:[0-9]+]]
36 const void *unit5(const int *arg
[5]) {
39 // CHECK: define dso_local ptr @unit5
40 // CHECK-NOT: getelementptr
41 // CHECK: call ptr @llvm.preserve.array.access.index.p0.p0(ptr elementtype(ptr) %{{[0-9a-z]+}}, i32 0, i32 1), !dbg !{{[0-9]+}}, !llvm.preserve.access.index !{{[0-9]+}}
42 // CHECK-NOT: getelementptr
43 // CHECK: call ptr @llvm.preserve.array.access.index.p0.p0(ptr elementtype(i32) %{{[0-9a-z]+}}, i32 0, i32 2), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[POINTER:[0-9]+]]
63 const void *unit6(struct s1
*arg
) {
66 // CHECK: define dso_local ptr @unit6
67 // CHECK-NOT: getelementptr
68 // CHECK: call ptr @llvm.preserve.struct.access.index.p0.p0(ptr elementtype(%struct.s1) %{{[0-9a-z]+}}, i32 0, i32 0), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[STRUCT_S1:[0-9]+]]
70 const void *unit7(struct s1
*arg
) {
73 // CHECK: define dso_local ptr @unit7
74 // CHECK-NOT: getelementptr
75 // CHECK: call ptr @llvm.preserve.struct.access.index.p0.p0(ptr elementtype(%struct.s1) %{{[0-9a-z]+}}, i32 1, i32 1), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[STRUCT_S1]]
77 const void *unit8(struct s2
*arg
) {
80 // CHECK: define dso_local ptr @unit8
81 // CHECK-NOT: getelementptr
82 // CHECK: call ptr @llvm.preserve.struct.access.index.p0.p0(ptr elementtype(%struct.s2) %{{[0-9a-z]+}}, i32 1, i32 2), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[STRUCT_S2:[0-9]+]]
84 const void *unit9(struct s3
*arg
) {
87 // CHECK: define dso_local ptr @unit9
88 // CHECK-NOT: getelementptr
89 // CHECK: call ptr @llvm.preserve.struct.access.index.p0.p0(ptr elementtype(%struct.s3) %{{[0-9a-z]+}}, i32 1, i32 2), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[STRUCT_S3:[0-9]+]]
102 const void *unit10(union u1
*arg
) {
105 // CHECK: define dso_local ptr @unit10
106 // CHECK-NOT: getelementptr
107 // CHECK: call ptr @llvm.preserve.union.access.index.p0.p0(ptr %{{[0-9a-z]+}}, i32 0), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[UNION_U1:[0-9]+]]
109 const void *unit11(union u1
*arg
) {
112 // CHECK: define dso_local ptr @unit11
113 // CHECK-NOT: getelementptr
114 // CHECK: call ptr @llvm.preserve.union.access.index.p0.p0(ptr %{{[0-9a-z]+}}, i32 1), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[UNION_U1]]
116 const void *unit12(union u2
*arg
) {
119 // CHECK: define dso_local ptr @unit12
120 // CHECK-NOT: getelementptr
121 // CHECK: call ptr @llvm.preserve.union.access.index.p0.p0(ptr %{{[0-9a-z]+}}, i32 1), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[UNION_U2:[0-9]+]]
138 const void *unit13(struct s4
*arg
) {
139 return _(&arg
->c
.b
[2]);
141 // CHECK: define dso_local ptr @unit13
142 // CHECK: call ptr @llvm.preserve.struct.access.index.p0.p0(ptr elementtype(%struct.s4) %{{[0-9a-z]+}}, i32 1, i32 1), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[STRUCT_S4:[0-9]+]]
143 // CHECK: call ptr @llvm.preserve.union.access.index.p0.p0(ptr %{{[0-9a-z]+}}, i32 0), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[UNION_I_U:[0-9]+]]
144 // CHECK: call ptr @llvm.preserve.array.access.index.p0.p0(ptr elementtype([4 x i32]) %{{[0-9a-z]+}}, i32 1, i32 2), !dbg !{{[0-9]+}}, !llvm.preserve.access.index !{{[0-9]+}}
146 const void *unit14(union u3
*arg
) {
147 return _(&arg
->c
.b
[2]);
149 // CHECK: define dso_local ptr @unit14
150 // CHECK: call ptr @llvm.preserve.union.access.index.p0.p0(ptr %{{[0-9a-z]+}}, i32 0), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[UNION_U3:[0-9]+]]
151 // CHECK: call ptr @llvm.preserve.struct.access.index.p0.p0(ptr elementtype(%struct.s) %{{[0-9a-z]+}}, i32 0, i32 0), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[STRUCT_I_S:[0-9]+]]
152 // CHECK: call ptr @llvm.preserve.array.access.index.p0.p0(ptr elementtype([4 x i32]) %{{[0-9a-z]+}}, i32 1, i32 2), !dbg !{{[0-9]+}}, !llvm.preserve.access.index !{{[0-9]+}}
154 const void *unit15(struct s4
*arg
) {
155 return _(&arg
[2].c
.a
);
157 // CHECK: define dso_local ptr @unit15
158 // CHECK: call ptr @llvm.preserve.array.access.index.p0.p0(ptr elementtype(%struct.s4) %{{[0-9a-z]+}}, i32 0, i32 2), !dbg !{{[0-9]+}}, !llvm.preserve.access.index !{{[0-9]+}}
159 // CHECK: call ptr @llvm.preserve.struct.access.index.p0.p0(ptr elementtype(%struct.s4) %{{[0-9a-z]+}}, i32 1, i32 1), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[STRUCT_S4]]
160 // CHECK: call ptr @llvm.preserve.union.access.index.p0.p0(ptr %{{[0-9a-z]+}}, i32 1), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[UNION_I_U]]
162 const void *unit16(union u3
*arg
) {
165 // CHECK: define dso_local ptr @unit16
166 // CHECK: call ptr @llvm.preserve.array.access.index.p0.p0(ptr elementtype(%union.u3) %{{[0-9a-z]+}}, i32 0, i32 2), !dbg !{{[0-9]+}}, !llvm.preserve.access.index !{{[0-9]+}}
167 // CHECK: call ptr @llvm.preserve.union.access.index.p0.p0(ptr %{{[0-9a-z]+}}, i32 1), !dbg !{{[0-9]+}}, !llvm.preserve.access.index ![[UNION_U3]]
169 // CHECK: ![[POINTER]] = !DIDerivedType(tag: DW_TAG_pointer_type
170 // CHECK: ![[STRUCT_S4]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s4"
171 // CHECK: ![[UNION_I_U]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: "u"
172 // CHECK: ![[UNION_U3]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: "u3"
173 // CHECK: ![[STRUCT_I_S]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s"
174 // CHECK: ![[STRUCT_S1]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s1"
175 // CHECK: ![[STRUCT_S2]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s2"
176 // CHECK: ![[STRUCT_S3]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s3"
177 // CHECK: ![[UNION_U1]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: "u1"
178 // CHECK: ![[UNION_U2]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: "u2"