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
4 ; typedef unsigned __uint;
5 ; struct s1 { int a1; __uint a2:9; __uint a3:4; };
6 ; union u1 { int b1; __uint b2:9; __uint b3:4; };
7 ; enum { FIELD_SIGNEDNESS = 3, };
8 ; int test(struct s1 *arg1, union u1 *arg2) {
9 ; unsigned r1 = __builtin_preserve_field_info(arg1->a1, FIELD_SIGNEDNESS);
10 ; unsigned r2 = __builtin_preserve_field_info(arg1->a3, FIELD_SIGNEDNESS);
11 ; unsigned r3 = __builtin_preserve_field_info(arg2->b1, FIELD_SIGNEDNESS);
12 ; unsigned r4 = __builtin_preserve_field_info(arg2->b3, FIELD_SIGNEDNESS);
13 ; return r1 + r2 + r3 + r4;
16 ; clang -target bpf -O2 -g -S -emit-llvm test.c
18 %struct.s1 = type { i32, i16 }
19 %union.u1 = type { i32 }
21 ; Function Attrs: nounwind readnone
22 define dso_local i32 @test(%struct.s1* %arg1, %union.u1* %arg2) local_unnamed_addr #0 !dbg !11 {
24 call void @llvm.dbg.value(metadata %struct.s1* %arg1, metadata !29, metadata !DIExpression()), !dbg !35
25 call void @llvm.dbg.value(metadata %union.u1* %arg2, metadata !30, metadata !DIExpression()), !dbg !35
26 %0 = tail call i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.s1s(%struct.s1* %arg1, i32 0, i32 0), !dbg !36, !llvm.preserve.access.index !16
27 %1 = tail call i32 @llvm.bpf.preserve.field.info.p0i32(i32* %0, i64 3), !dbg !37
28 call void @llvm.dbg.value(metadata i32 %1, metadata !31, metadata !DIExpression()), !dbg !35
29 %2 = tail call i16* @llvm.preserve.struct.access.index.p0i16.p0s_struct.s1s(%struct.s1* %arg1, i32 1, i32 2), !dbg !38, !llvm.preserve.access.index !16
30 %3 = tail call i32 @llvm.bpf.preserve.field.info.p0i16(i16* %2, i64 3), !dbg !39
31 call void @llvm.dbg.value(metadata i32 %3, metadata !32, metadata !DIExpression()), !dbg !35
32 %4 = tail call %union.u1* @llvm.preserve.union.access.index.p0s_union.u1s.p0s_union.u1s(%union.u1* %arg2, i32 0), !dbg !40, !llvm.preserve.access.index !23
33 %b1 = getelementptr inbounds %union.u1, %union.u1* %4, i64 0, i32 0, !dbg !40
34 %5 = tail call i32 @llvm.bpf.preserve.field.info.p0i32(i32* %b1, i64 3), !dbg !41
35 call void @llvm.dbg.value(metadata i32 %5, metadata !33, metadata !DIExpression()), !dbg !35
36 %6 = tail call i32* @llvm.preserve.struct.access.index.p0i32.p0s_union.u1s(%union.u1* %arg2, i32 0, i32 2), !dbg !42, !llvm.preserve.access.index !23
37 %7 = bitcast i32* %6 to i8*, !dbg !42
38 %8 = tail call i32 @llvm.bpf.preserve.field.info.p0i8(i8* %7, i64 3), !dbg !43
39 call void @llvm.dbg.value(metadata i32 %8, metadata !34, metadata !DIExpression()), !dbg !35
40 %add = add i32 %3, %1, !dbg !44
41 %add1 = add i32 %add, %5, !dbg !45
42 %add2 = add i32 %add1, %8, !dbg !46
43 ret i32 %add2, !dbg !47
55 ; CHECK: .long 1 # BTF_KIND_STRUCT(id = 2)
56 ; CHECK: .long 37 # BTF_KIND_UNION(id = 7)
57 ; CHECK: .ascii "s1" # string offset=1
58 ; CHECK: .ascii "u1" # string offset=37
59 ; CHECK: .ascii ".text" # string offset=64
60 ; CHECK: .ascii "0:0" # string offset=70
61 ; CHECK: .ascii "0:2" # string offset=111
63 ; CHECK: .long 16 # FieldReloc
64 ; CHECK-NEXT: .long 64 # Field reloc section string offset=64
66 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
68 ; CHECK-NEXT: .long 70
70 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
72 ; CHECK-NEXT: .long 111
74 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
76 ; CHECK-NEXT: .long 70
78 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
80 ; CHECK-NEXT: .long 111
83 ; Function Attrs: nounwind readnone
84 declare i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.s1s(%struct.s1*, i32, i32) #1
86 ; Function Attrs: nounwind readnone
87 declare i32 @llvm.bpf.preserve.field.info.p0i32(i32*, i64) #1
89 ; Function Attrs: nounwind readnone
90 declare i16* @llvm.preserve.struct.access.index.p0i16.p0s_struct.s1s(%struct.s1*, i32, i32) #1
92 ; Function Attrs: nounwind readnone
93 declare i32 @llvm.bpf.preserve.field.info.p0i16(i16*, i64) #1
95 ; Function Attrs: nounwind readnone
96 declare %union.u1* @llvm.preserve.union.access.index.p0s_union.u1s.p0s_union.u1s(%union.u1*, i32) #1
98 ; Function Attrs: nounwind readnone
99 declare i32* @llvm.preserve.struct.access.index.p0i32.p0s_union.u1s(%union.u1*, i32, i32) #1
101 ; Function Attrs: nounwind readnone
102 declare i32 @llvm.bpf.preserve.field.info.p0i8(i8*, i64) #1
104 ; Function Attrs: nounwind readnone speculatable willreturn
105 declare void @llvm.dbg.value(metadata, metadata, metadata) #2
107 attributes #0 = { nounwind readnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "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" }
108 attributes #1 = { nounwind readnone }
109 attributes #2 = { nounwind readnone speculatable willreturn }
112 !llvm.module.flags = !{!7, !8, !9}
115 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0 (https://github.com/llvm/llvm-project.git 4a60741b74384f14b21fdc0131ede326438840ab)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
116 !1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")
118 !3 = !DICompositeType(tag: DW_TAG_enumeration_type, file: !1, line: 4, baseType: !4, size: 32, elements: !5)
119 !4 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
121 !6 = !DIEnumerator(name: "FIELD_SIGNEDNESS", value: 3, isUnsigned: true)
122 !7 = !{i32 2, !"Dwarf Version", i32 4}
123 !8 = !{i32 2, !"Debug Info Version", i32 3}
124 !9 = !{i32 1, !"wchar_size", i32 4}
125 !10 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git 4a60741b74384f14b21fdc0131ede326438840ab)"}
126 !11 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 5, type: !12, scopeLine: 5, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !28)
127 !12 = !DISubroutineType(types: !13)
128 !13 = !{!14, !15, !22}
129 !14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
130 !15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !16, size: 64)
131 !16 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s1", file: !1, line: 2, size: 64, elements: !17)
132 !17 = !{!18, !19, !21}
133 !18 = !DIDerivedType(tag: DW_TAG_member, name: "a1", scope: !16, file: !1, line: 2, baseType: !14, size: 32)
134 !19 = !DIDerivedType(tag: DW_TAG_member, name: "a2", scope: !16, file: !1, line: 2, baseType: !20, size: 9, offset: 32, flags: DIFlagBitField, extraData: i64 32)
135 !20 = !DIDerivedType(tag: DW_TAG_typedef, name: "__uint", file: !1, line: 1, baseType: !4)
136 !21 = !DIDerivedType(tag: DW_TAG_member, name: "a3", scope: !16, file: !1, line: 2, baseType: !20, size: 4, offset: 41, flags: DIFlagBitField, extraData: i64 32)
137 !22 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !23, size: 64)
138 !23 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "u1", file: !1, line: 3, size: 32, elements: !24)
139 !24 = !{!25, !26, !27}
140 !25 = !DIDerivedType(tag: DW_TAG_member, name: "b1", scope: !23, file: !1, line: 3, baseType: !14, size: 32)
141 !26 = !DIDerivedType(tag: DW_TAG_member, name: "b2", scope: !23, file: !1, line: 3, baseType: !20, size: 9, flags: DIFlagBitField, extraData: i64 0)
142 !27 = !DIDerivedType(tag: DW_TAG_member, name: "b3", scope: !23, file: !1, line: 3, baseType: !20, size: 4, flags: DIFlagBitField, extraData: i64 0)
143 !28 = !{!29, !30, !31, !32, !33, !34}
144 !29 = !DILocalVariable(name: "arg1", arg: 1, scope: !11, file: !1, line: 5, type: !15)
145 !30 = !DILocalVariable(name: "arg2", arg: 2, scope: !11, file: !1, line: 5, type: !22)
146 !31 = !DILocalVariable(name: "r1", scope: !11, file: !1, line: 6, type: !4)
147 !32 = !DILocalVariable(name: "r2", scope: !11, file: !1, line: 7, type: !4)
148 !33 = !DILocalVariable(name: "r3", scope: !11, file: !1, line: 8, type: !4)
149 !34 = !DILocalVariable(name: "r4", scope: !11, file: !1, line: 9, type: !4)
150 !35 = !DILocation(line: 0, scope: !11)
151 !36 = !DILocation(line: 6, column: 53, scope: !11)
152 !37 = !DILocation(line: 6, column: 17, scope: !11)
153 !38 = !DILocation(line: 7, column: 53, scope: !11)
154 !39 = !DILocation(line: 7, column: 17, scope: !11)
155 !40 = !DILocation(line: 8, column: 53, scope: !11)
156 !41 = !DILocation(line: 8, column: 17, scope: !11)
157 !42 = !DILocation(line: 9, column: 53, scope: !11)
158 !43 = !DILocation(line: 9, column: 17, scope: !11)
159 !44 = !DILocation(line: 10, column: 13, scope: !11)
160 !45 = !DILocation(line: 10, column: 18, scope: !11)
161 !46 = !DILocation(line: 10, column: 23, scope: !11)
162 !47 = !DILocation(line: 10, column: 3, scope: !11)