xref: /llvm-project/llvm/test/Verifier/tbaa.ll (revision d065b1d65b11db9ecd92db5606327ee3bb3b9992)
1; RUN: not llvm-as < %s 2>&1 | FileCheck %s
2; RUN: llvm-as -disable-verify < %s | opt -passes=verify -S | FileCheck %s  --check-prefix=STRIP
3
4; STRIP-NOT: tbaa
5; STRIP: @f_0
6; STRIP: Do no strip this
7define void @f_0(ptr %ptr) {
8; This part checks for the easy syntactic verifier rules.
9
10; CHECK: Struct tag metadata must have either 3 or 4 operands
11; CHECK-NEXT:  store i32 0, ptr %ptr, align 4, !tbaa !{{[0-9]+}}
12
13; CHECK: Immutability tag on struct tag metadata must be a constant
14; CHECK-NEXT:  store i32 1, ptr %ptr, align 4, !tbaa !{{[0-9]+}}
15
16; CHECK: Immutability part of the struct tag metadata must be either 0 or 1
17; CHECK-NEXT:  store i32 2, ptr %ptr, align 4, !tbaa !{{[0-9]+}}
18
19; CHECK: Offset must be constant integer
20; CHECK-NEXT:  store i32 3, ptr %ptr, align 4, !tbaa !{{[0-9]+}}
21
22; CHECK: Malformed struct tag metadata:  base and access-type should be non-null and point to Metadata nodes
23; CHECK-NEXT:  store i32 4, ptr %ptr, align 4, !tbaa !{{[0-9]+}}
24
25; CHECK: Access type node must be a valid scalar type
26; CHECK-NEXT:  store i32 5, ptr %ptr, align 4, !tbaa !{{[0-9]+}}
27
28; CHECK: Access bit-width not the same as description bit-width
29; CHECK-NEXT:  store i32 6, ptr %ptr, align 4, !tbaa !{{[0-9]+}}
30
31; CHECK: Access type node must be a valid scalar type
32; CHECK-NEXT:  store i32 7, ptr %ptr, align 4, !tbaa !{{[0-9]+}}
33
34; CHECK: Struct tag nodes have a string as their first operand
35; CHECK-NEXT:  !{{[0-9]+}} = !{!{{[0-9]+}}, !{{[0-9]+}}, i64 0}
36
37; CHECK: Access type node must be a valid scalar type
38; CHECK-NEXT:  store i32 9, ptr %ptr, align 4, !tbaa !{{[0-9]+}}
39
40; CHECK: TBAA metadata cannot have 0 operands
41; CHECK-NEXT:  store i32 10, ptr %ptr, align 4, !tbaa !{{[0-9]+}}
42
43  store i32 0, ptr %ptr, !tbaa !{!3, !2, i64 40, i64 0, i64 1, i64 2}
44  store i32 1, ptr %ptr, !tbaa !{!3, !2, i64 40, !"immutable"}
45  store i32 2, ptr %ptr, !tbaa !{!3, !2, i64 40, i64 4}
46  store i32 3, ptr %ptr, !tbaa !{!3, !2, !"40", i64 0}
47  store i32 4, ptr %ptr, !tbaa !{!3, null, !"40", i64 0}
48  store i32 5, ptr %ptr, !tbaa !{!3, !3, !"40", i64 0}
49  store i32 6, ptr %ptr, !tbaa !{!3, !2, i32 40, i64 0}
50  store i32 7, ptr %ptr, !tbaa !{!3, !12, i32 40, i64 0}, !metadata !42
51  store i32 8, ptr %ptr, !tbaa !{!13, !1, i64 0}
52  store i32 9, ptr %ptr, !tbaa !{!14, !14, i64 0}
53  store i32 10, ptr %ptr, !tbaa !15
54  ret void
55}
56!42 = !{!"Do no strip this!"}
57
58define void @f_1(ptr %ptr) {
59; This part checks for more semantic verifier rules.
60
61; CHECK: Cycle detected in struct path
62; CHECK-NEXT:  store i32 0, ptr %ptr, align 4, !tbaa !{{[0-9]+}}
63
64; CHECK: Offset not zero at the point of scalar access
65; CHECK-NEXT:  store i32 1, ptr %ptr, align 4, !tbaa !{{[0-9]+}}
66
67; CHECK: Offset not zero at the point of scalar access
68; CHECK-NEXT:  store i32 2, ptr %ptr, align 4, !tbaa !{{[0-9]+}}
69
70; CHECK: Could not find TBAA parent in struct type node
71; CHECK-NEXT:  store i32 3, ptr %ptr, align 4, !tbaa !{{[0-9]+}}
72
73; CHECK: Did not see access type in access path!
74; CHECK-NEXT:  store i32 3, ptr %ptr, align 4, !tbaa !{{[0-9]+}}
75
76; CHECK: Access type node must be a valid scalar type
77; CHECK-NEXT:  store i32 4, ptr %ptr, align 4, !tbaa !{{[0-9]+}}
78
79; CHECK: Access type node must be a valid scalar type
80; CHECK-NEXT:  store i32 5, ptr %ptr, align 4, !tbaa !{{[0-9]+}}
81
82; CHECK: Access type node must be a valid scalar type
83; CHECK-NEXT:  store i32 6, ptr %ptr, align 4, !tbaa !{{[0-9]+}}
84
85; CHECK: Struct tag nodes must have an odd number of operands!
86; CHECK-NEXT:!{{[0-9]+}} = !{!"bad-struct-type-0", !{{[0-9]+}}, i64 40, !{{[0-9]+}}}
87
88; CHECK: Incorrect field entry in struct type node!
89; CHECK-NEXT:  store i32 8, ptr %ptr, align 4, !tbaa !{{[0-9]+}}
90
91; CHECK: Bitwidth between the offsets and struct type entries must match
92; CHECK-NEXT:  store i32 9, ptr %ptr, align 4, !tbaa !{{[0-9]+}}
93
94; CHECK: Offsets must be increasing!
95; CHECK-NEXT:  store i32 10, ptr %ptr, align 4, !tbaa !{{[0-9]+}}
96
97  store i32 0, ptr %ptr, !tbaa !{!4, !2, i64 40}
98  store i32 1, ptr %ptr, !tbaa !{!3, !2, i64 45}
99  store i32 2, ptr %ptr, !tbaa !{!3, !2, i64 45}
100  store i32 3, ptr %ptr, !tbaa !{!3, !2, i64 10}
101  store i32 4, ptr %ptr, !tbaa !{!5, !5, i64 0}
102  store i32 5, ptr %ptr, !tbaa !{!6, !6, i64 0}
103  store i32 6, ptr %ptr, !tbaa !{!7, !7, i64 0}
104  store i32 7, ptr %ptr, !tbaa !{!8, !1, i64 40}
105  store i32 8, ptr %ptr, !tbaa !{!9, !1, i64 40}
106  store i32 9, ptr %ptr, !tbaa !{!10, !1, i64 40}
107  store i32 10, ptr %ptr, !tbaa !{!11, !1, i64 40}
108  ret void
109}
110
111
112
113!0 = !{!"root"}
114!1 = !{!"scalar-a", !0}
115!2 = !{!"scalar-b", !0}
116!3 = !{!"struct-a", !2, i64 20, !1, i64 40}
117!4 = distinct !{!"self-recursive-struct", !2, i64 20, !4, i64 40}
118!5 = !{!"bad-scalar-0", i64 40}
119!6 = !{i64 42, !0}
120!7 = !{!"bad-scalar-1", null}
121!8 = !{!"bad-struct-type-0", !1, i64 40, !1}
122!9 = !{!"bad-struct-type-1", !1, i64 40, i64 56, !1}
123!10 = !{!"bad-struct-type-2", !1, i64 40, !1, i32 56}
124!11 = !{!"bad-struct-type-2", !1, i64 80, !1, i64 56}
125!12 = !{!"bad-scalar-2", !3, i64 0}
126!13 = !{!1, !1, i64 0}
127!14 = !{!"bad-scalar-2", !13}
128!15 = !{}
129