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 struct s1 { int a1; char a2; } __s1;
5 ; union u1 { int b1; __s1 b2; };
6 ; enum { FIELD_BYTE_SIZE = 1, };
7 ; int test(union u1 *arg) {
8 ; unsigned r1 = __builtin_preserve_field_info(arg->b2, FIELD_BYTE_SIZE);
9 ; unsigned r2 = __builtin_preserve_field_info(arg->b2.a1, FIELD_BYTE_SIZE);
10 ; unsigned r3 = __builtin_preserve_field_info(arg->b2.a2, FIELD_BYTE_SIZE);
11 ; /* r1: 8, r2: 4, r3: 1 */
12 ; return r1 + r2 + r3;
15 ; clang -target bpf -O2 -g -S -emit-llvm test.c
17 %union.u1 = type { %struct.s1 }
18 %struct.s1 = type { i32, i8 }
20 ; Function Attrs: nounwind readnone
21 define dso_local i32 @test(%union.u1* %arg) local_unnamed_addr #0 !dbg !11 {
23 call void @llvm.dbg.value(metadata %union.u1* %arg, metadata !27, metadata !DIExpression()), !dbg !31
24 %0 = tail call %union.u1* @llvm.preserve.union.access.index.p0s_union.u1s.p0s_union.u1s(%union.u1* %arg, i32 1), !dbg !32, !llvm.preserve.access.index !16
25 %b2 = getelementptr inbounds %union.u1, %union.u1* %0, i64 0, i32 0, !dbg !32
26 %1 = tail call i32 @llvm.bpf.preserve.field.info.p0s_struct.s1s(%struct.s1* %b2, i64 1), !dbg !33
27 call void @llvm.dbg.value(metadata i32 %1, metadata !28, metadata !DIExpression()), !dbg !31
28 %2 = tail call i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.s1s(%struct.s1* %b2, i32 0, i32 0), !dbg !34, !llvm.preserve.access.index !21
29 %3 = tail call i32 @llvm.bpf.preserve.field.info.p0i32(i32* %2, i64 1), !dbg !35
30 call void @llvm.dbg.value(metadata i32 %3, metadata !29, metadata !DIExpression()), !dbg !31
31 %4 = tail call i8* @llvm.preserve.struct.access.index.p0i8.p0s_struct.s1s(%struct.s1* %b2, i32 1, i32 1), !dbg !36, !llvm.preserve.access.index !21
32 %5 = tail call i32 @llvm.bpf.preserve.field.info.p0i8(i8* %4, i64 1), !dbg !37
33 call void @llvm.dbg.value(metadata i32 %5, metadata !30, metadata !DIExpression()), !dbg !31
34 %add = add i32 %3, %1, !dbg !38
35 %add3 = add i32 %add, %5, !dbg !39
36 ret i32 %add3, !dbg !40
46 ; CHECK: .long 1 # BTF_KIND_UNION(id = 2)
47 ; CHECK: .ascii "u1" # string offset=1
48 ; CHECK: .ascii ".text" # string offset=42
49 ; CHECK: .ascii "0:1" # string offset=48
50 ; CHECK: .ascii "0:1:0" # string offset=89
51 ; CHECK: .ascii "0:1:1" # string offset=95
53 ; CHECK: .long 16 # FieldReloc
54 ; CHECK-NEXT: .long 42 # Field reloc section string offset=42
56 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
58 ; CHECK-NEXT: .long 48
60 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
62 ; CHECK-NEXT: .long 89
64 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
66 ; CHECK-NEXT: .long 95
69 ; Function Attrs: nounwind readnone
70 declare %union.u1* @llvm.preserve.union.access.index.p0s_union.u1s.p0s_union.u1s(%union.u1*, i32) #1
72 ; Function Attrs: nounwind readnone
73 declare i32 @llvm.bpf.preserve.field.info.p0s_struct.s1s(%struct.s1*, i64) #1
75 ; Function Attrs: nounwind readnone
76 declare i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.s1s(%struct.s1*, i32, i32) #1
78 ; Function Attrs: nounwind readnone
79 declare i32 @llvm.bpf.preserve.field.info.p0i32(i32*, i64) #1
81 ; Function Attrs: nounwind readnone
82 declare i8* @llvm.preserve.struct.access.index.p0i8.p0s_struct.s1s(%struct.s1*, i32, i32) #1
84 ; Function Attrs: nounwind readnone
85 declare i32 @llvm.bpf.preserve.field.info.p0i8(i8*, i64) #1
87 ; Function Attrs: nounwind readnone speculatable willreturn
88 declare void @llvm.dbg.value(metadata, metadata, metadata) #2
90 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" }
91 attributes #1 = { nounwind readnone }
92 attributes #2 = { nounwind readnone speculatable willreturn }
95 !llvm.module.flags = !{!7, !8, !9}
98 !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)
99 !1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")
101 !3 = !DICompositeType(tag: DW_TAG_enumeration_type, file: !1, line: 3, baseType: !4, size: 32, elements: !5)
102 !4 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
104 !6 = !DIEnumerator(name: "FIELD_BYTE_SIZE", value: 1, isUnsigned: true)
105 !7 = !{i32 2, !"Dwarf Version", i32 4}
106 !8 = !{i32 2, !"Debug Info Version", i32 3}
107 !9 = !{i32 1, !"wchar_size", i32 4}
108 !10 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git 4a60741b74384f14b21fdc0131ede326438840ab)"}
109 !11 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 4, type: !12, scopeLine: 4, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !26)
110 !12 = !DISubroutineType(types: !13)
112 !14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
113 !15 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !16, size: 64)
114 !16 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "u1", file: !1, line: 2, size: 64, elements: !17)
116 !18 = !DIDerivedType(tag: DW_TAG_member, name: "b1", scope: !16, file: !1, line: 2, baseType: !14, size: 32)
117 !19 = !DIDerivedType(tag: DW_TAG_member, name: "b2", scope: !16, file: !1, line: 2, baseType: !20, size: 64)
118 !20 = !DIDerivedType(tag: DW_TAG_typedef, name: "__s1", file: !1, line: 1, baseType: !21)
119 !21 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s1", file: !1, line: 1, size: 64, elements: !22)
121 !23 = !DIDerivedType(tag: DW_TAG_member, name: "a1", scope: !21, file: !1, line: 1, baseType: !14, size: 32)
122 !24 = !DIDerivedType(tag: DW_TAG_member, name: "a2", scope: !21, file: !1, line: 1, baseType: !25, size: 8, offset: 32)
123 !25 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
124 !26 = !{!27, !28, !29, !30}
125 !27 = !DILocalVariable(name: "arg", arg: 1, scope: !11, file: !1, line: 4, type: !15)
126 !28 = !DILocalVariable(name: "r1", scope: !11, file: !1, line: 5, type: !4)
127 !29 = !DILocalVariable(name: "r2", scope: !11, file: !1, line: 6, type: !4)
128 !30 = !DILocalVariable(name: "r3", scope: !11, file: !1, line: 7, type: !4)
129 !31 = !DILocation(line: 0, scope: !11)
130 !32 = !DILocation(line: 5, column: 52, scope: !11)
131 !33 = !DILocation(line: 5, column: 17, scope: !11)
132 !34 = !DILocation(line: 6, column: 55, scope: !11)
133 !35 = !DILocation(line: 6, column: 17, scope: !11)
134 !36 = !DILocation(line: 7, column: 55, scope: !11)
135 !37 = !DILocation(line: 7, column: 17, scope: !11)
136 !38 = !DILocation(line: 9, column: 13, scope: !11)
137 !39 = !DILocation(line: 9, column: 18, scope: !11)
138 !40 = !DILocation(line: 9, column: 3, scope: !11)