1; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
2; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
3; Source code:
4;    struct sk_buff {
5;      int i;
6;      struct net_device *dev;
7;    };
8;    #define _(x) (__builtin_preserve_access_index(x))
9;    static int (*bpf_probe_read)(void *dst, int size, void *unsafe_ptr)
10;        = (void *) 4;
11;
12;    int bpf_prog(struct sk_buff *ctx) {
13;      struct net_device *dev = 0;
14;      bpf_probe_read(&dev, sizeof(dev), _(&ctx->dev));
15;      return dev != 0;
16;    }
17; Compilation flag:
18;   clang -target bpf -O2 -g -S -emit-llvm test.c
19
20%struct.sk_buff = type { i32, %struct.net_device* }
21%struct.net_device = type opaque
22
23; Function Attrs: nounwind
24define dso_local i32 @bpf_prog(%struct.sk_buff*) local_unnamed_addr #0 !dbg !15 {
25  %2 = alloca %struct.net_device*, align 8
26  call void @llvm.dbg.value(metadata %struct.sk_buff* %0, metadata !26, metadata !DIExpression()), !dbg !28
27  %3 = bitcast %struct.net_device** %2 to i8*, !dbg !29
28  call void @llvm.lifetime.start.p0i8(i64 8, i8* nonnull %3) #4, !dbg !29
29  call void @llvm.dbg.value(metadata %struct.net_device* null, metadata !27, metadata !DIExpression()), !dbg !28
30  store %struct.net_device* null, %struct.net_device** %2, align 8, !dbg !30, !tbaa !31
31  %4 = tail call %struct.net_device** @llvm.preserve.struct.access.index.p0p0s_struct.net_devices.p0s_struct.sk_buffs(%struct.sk_buff* %0, i32 1, i32 1), !dbg !35, !llvm.preserve.access.index !19
32  %5 = bitcast %struct.net_device** %4 to i8*, !dbg !35
33  %6 = call i32 inttoptr (i64 4 to i32 (i8*, i32, i8*)*)(i8* nonnull %3, i32 8, i8* %5) #4, !dbg !36
34  %7 = load %struct.net_device*, %struct.net_device** %2, align 8, !dbg !37, !tbaa !31
35  call void @llvm.dbg.value(metadata %struct.net_device* %7, metadata !27, metadata !DIExpression()), !dbg !28
36  %8 = icmp ne %struct.net_device* %7, null, !dbg !38
37  %9 = zext i1 %8 to i32, !dbg !38
38  call void @llvm.lifetime.end.p0i8(i64 8, i8* nonnull %3) #4, !dbg !39
39  ret i32 %9, !dbg !40
40}
41
42; CHECK:             .section        .BTF,"",@progbits
43; CHECK-NEXT:        .short  60319                   # 0xeb9f
44; CHECK-NEXT:        .byte   1
45; CHECK-NEXT:        .byte   0
46; CHECK-NEXT:        .long   24
47; CHECK-NEXT:        .long   0
48; CHECK-NEXT:        .long   120
49; CHECK-NEXT:        .long   120
50; CHECK-NEXT:        .long   90
51; CHECK-NEXT:        .long   0                       # BTF_KIND_PTR(id = 1)
52; CHECK-NEXT:        .long   33554432                # 0x2000000
53; CHECK-NEXT:        .long   2
54; CHECK-NEXT:        .long   1                       # BTF_KIND_STRUCT(id = 2)
55; CHECK-NEXT:        .long   67108866                # 0x4000002
56; CHECK-NEXT:        .long   16
57; CHECK-NEXT:        .long   9
58; CHECK-NEXT:        .long   3
59; CHECK-NEXT:        .long   0                       # 0x0
60; CHECK-NEXT:        .long   11
61; CHECK-NEXT:        .long   4
62; CHECK-NEXT:        .long   64                      # 0x40
63; CHECK-NEXT:        .long   15                      # BTF_KIND_INT(id = 3)
64; CHECK-NEXT:        .long   16777216                # 0x1000000
65; CHECK-NEXT:        .long   4
66; CHECK-NEXT:        .long   16777248                # 0x1000020
67; CHECK-NEXT:        .long   0                       # BTF_KIND_PTR(id = 4)
68; CHECK-NEXT:        .long   33554432                # 0x2000000
69; CHECK-NEXT:        .long   5
70; CHECK-NEXT:        .long   19                      # BTF_KIND_FWD(id = 5)
71; CHECK-NEXT:        .long   117440512               # 0x7000000
72; CHECK-NEXT:        .long   0
73; CHECK-NEXT:        .long   0                       # BTF_KIND_FUNC_PROTO(id = 6)
74; CHECK-NEXT:        .long   218103809               # 0xd000001
75; CHECK-NEXT:        .long   3
76; CHECK-NEXT:        .long   30
77; CHECK-NEXT:        .long   1
78; CHECK-NEXT:        .long   34                      # BTF_KIND_FUNC(id = 7)
79; CHECK-NEXT:        .long   201326592               # 0xc000000
80; CHECK-NEXT:        .long   6
81; CHECK-NEXT:        .byte   0                       # string offset=0
82; CHECK-NEXT:        .ascii  "sk_buff"               # string offset=1
83; CHECK-NEXT:        .byte   0
84; CHECK-NEXT:        .byte   105                     # string offset=9
85; CHECK-NEXT:        .byte   0
86; CHECK-NEXT:        .ascii  "dev"                   # string offset=11
87; CHECK-NEXT:        .byte   0
88; CHECK-NEXT:        .ascii  "int"                   # string offset=15
89; CHECK-NEXT:        .byte   0
90; CHECK-NEXT:        .ascii  "net_device"            # string offset=19
91; CHECK-NEXT:        .byte   0
92; CHECK-NEXT:        .ascii  "ctx"                   # string offset=30
93; CHECK-NEXT:        .byte   0
94; CHECK-NEXT:        .ascii  "bpf_prog"              # string offset=34
95; CHECK-NEXT:        .byte   0
96; CHECK-NEXT:        .ascii  ".text"                 # string offset=43
97; CHECK-NEXT:        .byte   0
98; CHECK-NEXT:        .ascii  "/tmp/home/yhs/work/tests/llvm/test.c" # string offset=49
99; CHECK-NEXT:        .byte   0
100; CHECK-NEXT:        .ascii  "0:1"                   # string offset=86
101; CHECK-NEXT:        .byte   0
102; CHECK-NEXT:        .section        .BTF.ext,"",@progbits
103; CHECK-NEXT:        .short  60319                   # 0xeb9f
104; CHECK-NEXT:        .byte   1
105; CHECK-NEXT:        .byte   0
106; CHECK-NEXT:        .long   40
107; CHECK-NEXT:        .long   0
108; CHECK-NEXT:        .long   20
109; CHECK-NEXT:        .long   20
110; CHECK-NEXT:        .long   124
111; CHECK-NEXT:        .long   144
112; CHECK-NEXT:        .long   24
113; CHECK-NEXT:        .long   168
114; CHECK-NEXT:        .long   0
115; CHECK-NEXT:        .long   8                       # FuncInfo
116
117; CHECK:             .long   12                      # OffsetReloc
118; CHECK-NEXT:        .long   43                      # Offset reloc section string offset=43
119; CHECK-NEXT:        .long   1
120; CHECK-NEXT:        .long   .Ltmp2
121; CHECK-NEXT:        .long   2
122; CHECK-NEXT:        .long   86
123
124; Function Attrs: argmemonly nounwind
125declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #1
126
127; Function Attrs: nounwind readnone
128declare %struct.net_device** @llvm.preserve.struct.access.index.p0p0s_struct.net_devices.p0s_struct.sk_buffs(%struct.sk_buff*, i32 immarg, i32 immarg) #2
129
130; Function Attrs: argmemonly nounwind
131declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #1
132
133; Function Attrs: nounwind readnone speculatable
134declare void @llvm.dbg.value(metadata, metadata, metadata) #3
135
136attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "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" }
137attributes #1 = { argmemonly nounwind }
138attributes #2 = { nounwind readnone }
139attributes #3 = { nounwind readnone speculatable }
140attributes #4 = { nounwind }
141
142!llvm.dbg.cu = !{!0}
143!llvm.module.flags = !{!11, !12, !13}
144!llvm.ident = !{!14}
145
146!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)
147!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm")
148!2 = !{}
149!3 = !{!4}
150!4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression())
151!5 = distinct !DIGlobalVariable(name: "bpf_probe_read", scope: !0, file: !1, line: 6, type: !6, isLocal: true, isDefinition: true)
152!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64)
153!7 = !DISubroutineType(types: !8)
154!8 = !{!9, !10, !9, !10}
155!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
156!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
157!11 = !{i32 2, !"Dwarf Version", i32 4}
158!12 = !{i32 2, !"Debug Info Version", i32 3}
159!13 = !{i32 1, !"wchar_size", i32 4}
160!14 = !{!"clang version 9.0.0 (trunk 360739) (llvm/trunk 360747)"}
161!15 = distinct !DISubprogram(name: "bpf_prog", scope: !1, file: !1, line: 9, type: !16, scopeLine: 9, flags: DIFlagPrototyped, isLocal: false, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !25)
162!16 = !DISubroutineType(types: !17)
163!17 = !{!9, !18}
164!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
165!19 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "sk_buff", file: !1, line: 1, size: 128, elements: !20)
166!20 = !{!21, !22}
167!21 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !19, file: !1, line: 2, baseType: !9, size: 32)
168!22 = !DIDerivedType(tag: DW_TAG_member, name: "dev", scope: !19, file: !1, line: 3, baseType: !23, size: 64, offset: 64)
169!23 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !24, size: 64)
170!24 = !DICompositeType(tag: DW_TAG_structure_type, name: "net_device", file: !1, line: 3, flags: DIFlagFwdDecl)
171!25 = !{!26, !27}
172!26 = !DILocalVariable(name: "ctx", arg: 1, scope: !15, file: !1, line: 9, type: !18)
173!27 = !DILocalVariable(name: "dev", scope: !15, file: !1, line: 10, type: !23)
174!28 = !DILocation(line: 0, scope: !15)
175!29 = !DILocation(line: 10, column: 3, scope: !15)
176!30 = !DILocation(line: 10, column: 22, scope: !15)
177!31 = !{!32, !32, i64 0}
178!32 = !{!"any pointer", !33, i64 0}
179!33 = !{!"omnipotent char", !34, i64 0}
180!34 = !{!"Simple C/C++ TBAA"}
181!35 = !DILocation(line: 11, column: 37, scope: !15)
182!36 = !DILocation(line: 11, column: 3, scope: !15)
183!37 = !DILocation(line: 12, column: 10, scope: !15)
184!38 = !DILocation(line: 12, column: 14, scope: !15)
185!39 = !DILocation(line: 13, column: 1, scope: !15)
186!40 = !DILocation(line: 12, column: 3, scope: !15)
187