xref: /llvm-project/llvm/test/CodeGen/BPF/CORE/offset-reloc-struct-anonymous.ll (revision 60228733726e25d011b1f9221e005732191cc077)
1; RUN: opt -O2 %s | llvm-dis > %t1
2; RUN: llc -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK %s
3; RUN: llc -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK %s
4; Source code:
5;   struct sk_buff {
6;     int i;
7;     struct {
8;       int dev_id;
9;       int others;
10;     } dev[10];
11;   };
12;   #define _(x) (__builtin_preserve_access_index(x))
13;   static int (*bpf_probe_read)(ptr dst, int size, ptr unsafe_ptr)
14;       = (ptr) 4;
15;
16;   int bpf_prog(struct sk_buff *ctx) {
17;     int dev_id;
18;     bpf_probe_read(&dev_id, sizeof(int), _(&ctx->dev[5].dev_id));
19;     return dev_id;
20;   }
21; Compilation flag:
22;   clang -target bpf -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c
23
24target triple = "bpf"
25
26%struct.sk_buff = type { i32, [10 x %struct.anon] }
27%struct.anon = type { i32, i32 }
28
29; Function Attrs: nounwind
30define dso_local i32 @bpf_prog(ptr) local_unnamed_addr #0 !dbg !15 {
31  %2 = alloca i32, align 4
32  call void @llvm.dbg.value(metadata ptr %0, metadata !31, metadata !DIExpression()), !dbg !33
33  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4, !dbg !34
34  %3 = tail call ptr @llvm.preserve.struct.access.index.p0.anons.p0.sk_buffs(ptr elementtype(%struct.sk_buff) %0, i32 1, i32 1), !dbg !35, !llvm.preserve.access.index !19
35  %4 = tail call ptr @llvm.preserve.array.access.index.p0.anons.p0.anons(ptr elementtype([10 x %struct.anon]) %3, i32 1, i32 5), !dbg !35, !llvm.preserve.access.index !23
36  %5 = tail call ptr @llvm.preserve.struct.access.index.p0.p0.anons(ptr elementtype(%struct.anon) %4, i32 0, i32 0), !dbg !35, !llvm.preserve.access.index !24
37  %6 = call i32 inttoptr (i64 4 to ptr)(ptr nonnull %2, i32 4, ptr %5) #4, !dbg !36
38  %7 = load i32, ptr %2, align 4, !dbg !37, !tbaa !38
39  call void @llvm.dbg.value(metadata i32 %7, metadata !32, metadata !DIExpression()), !dbg !33
40  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4, !dbg !42
41  ret i32 %7, !dbg !43
42}
43
44; CHECK:             .section        .BTF,"",@progbits
45; CHECK-NEXT:        .short  60319                   # 0xeb9f
46; CHECK-NEXT:        .byte   1
47; CHECK-NEXT:        .byte   0
48; CHECK-NEXT:        .long   24
49; CHECK-NEXT:        .long   0
50; CHECK-NEXT:        .long   172
51; CHECK-NEXT:        .long   172
52; CHECK-NEXT:        .long   117
53; CHECK-NEXT:        .long   0                       # BTF_KIND_PTR(id = 1)
54; CHECK-NEXT:        .long   33554432                # 0x2000000
55; CHECK-NEXT:        .long   2
56; CHECK-NEXT:        .long   1                       # BTF_KIND_STRUCT(id = 2)
57; CHECK-NEXT:        .long   67108866                # 0x4000002
58; CHECK-NEXT:        .long   84
59; CHECK-NEXT:        .long   9
60; CHECK-NEXT:        .long   3
61; CHECK-NEXT:        .long   0                       # 0x0
62; CHECK-NEXT:        .long   11
63; CHECK-NEXT:        .long   5
64; CHECK-NEXT:        .long   32                      # 0x20
65; CHECK-NEXT:        .long   15                      # BTF_KIND_INT(id = 3)
66; CHECK-NEXT:        .long   16777216                # 0x1000000
67; CHECK-NEXT:        .long   4
68; CHECK-NEXT:        .long   16777248                # 0x1000020
69; CHECK-NEXT:        .long   0                       # BTF_KIND_STRUCT(id = 4)
70; CHECK-NEXT:        .long   67108866                # 0x4000002
71; CHECK-NEXT:        .long   8
72; CHECK-NEXT:        .long   19
73; CHECK-NEXT:        .long   3
74; CHECK-NEXT:        .long   0                       # 0x0
75; CHECK-NEXT:        .long   26
76; CHECK-NEXT:        .long   3
77; CHECK-NEXT:        .long   32                      # 0x20
78; CHECK-NEXT:        .long   0                       # BTF_KIND_ARRAY(id = 5)
79; CHECK-NEXT:        .long   50331648                # 0x3000000
80; CHECK-NEXT:        .long   0
81; CHECK-NEXT:        .long   4
82; CHECK-NEXT:        .long   6
83; CHECK-NEXT:        .long   10
84; CHECK-NEXT:        .long   33                      # BTF_KIND_INT(id = 6)
85; CHECK-NEXT:        .long   16777216                # 0x1000000
86; CHECK-NEXT:        .long   4
87; CHECK-NEXT:        .long   32                      # 0x20
88; CHECK-NEXT:        .long   0                       # BTF_KIND_FUNC_PROTO(id = 7)
89; CHECK-NEXT:        .long   218103809               # 0xd000001
90; CHECK-NEXT:        .long   3
91; CHECK-NEXT:        .long   53
92; CHECK-NEXT:        .long   1
93; CHECK-NEXT:        .long   57                      # BTF_KIND_FUNC(id = 8)
94; CHECK-NEXT:        .long   201326593               # 0xc000001
95; CHECK-NEXT:        .long   7
96; CHECK-NEXT:        .byte   0                       # string offset=0
97; CHECK-NEXT:        .ascii  "sk_buff"               # string offset=1
98; CHECK-NEXT:        .byte   0
99; CHECK-NEXT:        .byte   105                     # string offset=9
100; CHECK-NEXT:        .byte   0
101; CHECK-NEXT:        .ascii  "dev"                   # string offset=11
102; CHECK-NEXT:        .byte   0
103; CHECK-NEXT:        .ascii  "int"                   # string offset=15
104; CHECK-NEXT:        .byte   0
105; CHECK-NEXT:        .ascii  "dev_id"                # string offset=19
106; CHECK-NEXT:        .byte   0
107; CHECK-NEXT:        .ascii  "others"                # string offset=26
108; CHECK-NEXT:        .byte   0
109; CHECK-NEXT:        .ascii  "__ARRAY_SIZE_TYPE__"   # string offset=33
110; CHECK-NEXT:        .byte   0
111; CHECK-NEXT:        .ascii  "ctx"                   # string offset=53
112; CHECK-NEXT:        .byte   0
113; CHECK-NEXT:        .ascii  "bpf_prog"              # string offset=57
114; CHECK-NEXT:        .byte   0
115; CHECK-NEXT:        .ascii  ".text"                 # string offset=66
116; CHECK-NEXT:        .byte   0
117; CHECK-NEXT:        .ascii  "/tmp/home/yhs/work/tests/llvm/test.c" # string offset=72
118; CHECK-NEXT:        .byte   0
119; CHECK-NEXT:        .ascii  "0:1:5:0"               # string offset=109
120; CHECK-NEXT:        .byte   0
121; CHECK-NEXT:        .section        .BTF.ext,"",@progbits
122; CHECK-NEXT:        .short  60319                   # 0xeb9f
123; CHECK-NEXT:        .byte   1
124; CHECK-NEXT:        .byte   0
125; CHECK-NEXT:        .long   32
126; CHECK-NEXT:        .long   0
127; CHECK-NEXT:        .long   20
128; CHECK-NEXT:        .long   20
129; CHECK-NEXT:        .long   {{[0-9]+}}
130; CHECK-NEXT:        .long   {{[0-9]+}}
131; CHECK-NEXT:        .long   28
132; CHECK-NEXT:        .long   8                       # FuncInfo
133
134; CHECK:             .long   16                      # FieldReloc
135; CHECK-NEXT:        .long   66                      # Field reloc section string offset=66
136; CHECK-NEXT:        .long   1
137; CHECK-NEXT:        .long   .Ltmp{{[0-9]+}}
138; CHECK-NEXT:        .long   2
139; CHECK-NEXT:        .long   109
140; CHECK-NEXT:        .long   0
141
142; Function Attrs: argmemonly nounwind
143declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1
144
145; Function Attrs: nounwind readnone
146declare ptr @llvm.preserve.struct.access.index.p0.anons.p0.sk_buffs(ptr, i32 immarg, i32 immarg) #2
147
148; Function Attrs: nounwind readnone
149declare ptr @llvm.preserve.array.access.index.p0.anons.p0.anons(ptr, i32 immarg, i32 immarg) #2
150
151; Function Attrs: nounwind readnone
152declare ptr @llvm.preserve.struct.access.index.p0.p0.anons(ptr, i32 immarg, i32 immarg) #2
153
154; Function Attrs: argmemonly nounwind
155declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1
156
157; Function Attrs: nounwind readnone speculatable
158declare void @llvm.dbg.value(metadata, metadata, metadata) #3
159
160attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "frame-pointer"="all" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
161attributes #1 = { argmemonly nounwind }
162attributes #2 = { nounwind readnone }
163attributes #3 = { nounwind readnone speculatable }
164attributes #4 = { nounwind }
165
166!llvm.dbg.cu = !{!0}
167!llvm.module.flags = !{!11, !12, !13}
168!llvm.ident = !{!14}
169
170!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (trunk 360739) (llvm/trunk 360747)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3, nameTableKind: None)
171!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm")
172!2 = !{}
173!3 = !{!4}
174!4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression())
175!5 = distinct !DIGlobalVariable(name: "bpf_probe_read", scope: !0, file: !1, line: 9, type: !6, isLocal: true, isDefinition: true)
176!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64)
177!7 = !DISubroutineType(types: !8)
178!8 = !{!9, !10, !9, !10}
179!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
180!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
181!11 = !{i32 2, !"Dwarf Version", i32 4}
182!12 = !{i32 2, !"Debug Info Version", i32 3}
183!13 = !{i32 1, !"wchar_size", i32 4}
184!14 = !{!"clang version 9.0.0 (trunk 360739) (llvm/trunk 360747)"}
185!15 = distinct !DISubprogram(name: "bpf_prog", scope: !1, file: !1, line: 12, type: !16, scopeLine: 12, flags: DIFlagPrototyped, isLocal: false, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !30)
186!16 = !DISubroutineType(types: !17)
187!17 = !{!9, !18}
188!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
189!19 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "sk_buff", file: !1, line: 1, size: 672, elements: !20)
190!20 = !{!21, !22}
191!21 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !19, file: !1, line: 2, baseType: !9, size: 32)
192!22 = !DIDerivedType(tag: DW_TAG_member, name: "dev", scope: !19, file: !1, line: 6, baseType: !23, size: 640, offset: 32)
193!23 = !DICompositeType(tag: DW_TAG_array_type, baseType: !24, size: 640, elements: !28)
194!24 = distinct !DICompositeType(tag: DW_TAG_structure_type, scope: !19, file: !1, line: 3, size: 64, elements: !25)
195!25 = !{!26, !27}
196!26 = !DIDerivedType(tag: DW_TAG_member, name: "dev_id", scope: !24, file: !1, line: 4, baseType: !9, size: 32)
197!27 = !DIDerivedType(tag: DW_TAG_member, name: "others", scope: !24, file: !1, line: 5, baseType: !9, size: 32, offset: 32)
198!28 = !{!29}
199!29 = !DISubrange(count: 10)
200!30 = !{!31, !32}
201!31 = !DILocalVariable(name: "ctx", arg: 1, scope: !15, file: !1, line: 12, type: !18)
202!32 = !DILocalVariable(name: "dev_id", scope: !15, file: !1, line: 13, type: !9)
203!33 = !DILocation(line: 0, scope: !15)
204!34 = !DILocation(line: 13, column: 3, scope: !15)
205!35 = !DILocation(line: 14, column: 40, scope: !15)
206!36 = !DILocation(line: 14, column: 3, scope: !15)
207!37 = !DILocation(line: 15, column: 10, scope: !15)
208!38 = !{!39, !39, i64 0}
209!39 = !{!"int", !40, i64 0}
210!40 = !{!"omnipotent char", !41, i64 0}
211!41 = !{!"Simple C/C++ TBAA"}
212!42 = !DILocation(line: 16, column: 1, scope: !15)
213!43 = !DILocation(line: 15, column: 3, scope: !15)
214