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; union sk_buff { 6; int i; 7; struct { 8; int netid; 9; union { 10; int dev_id; 11; int others; 12; } dev; 13; } u; 14; }; 15; #define _(x) (__builtin_preserve_access_index(x)) 16; static int (*bpf_probe_read)(void *dst, int size, void *unsafe_ptr) 17; = (void *) 4; 18; 19; int bpf_prog(union sk_buff *ctx) { 20; int dev_id; 21; bpf_probe_read(&dev_id, sizeof(int), _(&ctx->u.dev.dev_id)); 22; return dev_id; 23; } 24; Compilation flag: 25; clang -target bpf -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c 26 27target triple = "bpf" 28 29%union.sk_buff = type { %struct.anon } 30%struct.anon = type { i32, %union.anon } 31%union.anon = type { i32 } 32 33; Function Attrs: nounwind 34define dso_local i32 @bpf_prog(%union.sk_buff*) local_unnamed_addr #0 !dbg !15 { 35 %2 = alloca i32, align 4 36 call void @llvm.dbg.value(metadata %union.sk_buff* %0, metadata !32, metadata !DIExpression()), !dbg !34 37 %3 = bitcast i32* %2 to i8*, !dbg !35 38 call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %3) #4, !dbg !35 39 %4 = tail call %union.sk_buff* @llvm.preserve.union.access.index.p0s_union.sk_buffs.p0s_union.sk_buffs(%union.sk_buff* %0, i32 1), !dbg !36, !llvm.preserve.access.index !19 40 %5 = getelementptr inbounds %union.sk_buff, %union.sk_buff* %4, i64 0, i32 0, !dbg !36 41 %6 = tail call %union.anon* @llvm.preserve.struct.access.index.p0s_union.anons.p0s_struct.anons(%struct.anon* %5, i32 1, i32 1), !dbg !36, !llvm.preserve.access.index !23 42 %7 = tail call %union.anon* @llvm.preserve.union.access.index.p0s_union.anons.p0s_union.anons(%union.anon* %6, i32 0), !dbg !36, !llvm.preserve.access.index !27 43 %8 = bitcast %union.anon* %7 to i8*, !dbg !36 44 %9 = call i32 inttoptr (i64 4 to i32 (i8*, i32, i8*)*)(i8* nonnull %3, i32 4, i8* %8) #4, !dbg !37 45 %10 = load i32, i32* %2, align 4, !dbg !38, !tbaa !39 46 call void @llvm.dbg.value(metadata i32 %10, metadata !33, metadata !DIExpression()), !dbg !34 47 call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %3) #4, !dbg !43 48 ret i32 %10, !dbg !44 49} 50 51; CHECK: .section .BTF,"",@progbits 52; CHECK-NEXT: .short 60319 # 0xeb9f 53; CHECK-NEXT: .byte 1 54; CHECK-NEXT: .byte 0 55; CHECK-NEXT: .long 24 56; CHECK-NEXT: .long 0 57; CHECK-NEXT: .long 168 58; CHECK-NEXT: .long 168 59; CHECK-NEXT: .long 105 60; CHECK-NEXT: .long 0 # BTF_KIND_PTR(id = 1) 61; CHECK-NEXT: .long 33554432 # 0x2000000 62; CHECK-NEXT: .long 2 63; CHECK-NEXT: .long 1 # BTF_KIND_UNION(id = 2) 64; CHECK-NEXT: .long 83886082 # 0x5000002 65; CHECK-NEXT: .long 8 66; CHECK-NEXT: .long 9 67; CHECK-NEXT: .long 3 68; CHECK-NEXT: .long 0 # 0x0 69; CHECK-NEXT: .long 11 70; CHECK-NEXT: .long 4 71; CHECK-NEXT: .long 0 # 0x0 72; CHECK-NEXT: .long 13 # BTF_KIND_INT(id = 3) 73; CHECK-NEXT: .long 16777216 # 0x1000000 74; CHECK-NEXT: .long 4 75; CHECK-NEXT: .long 16777248 # 0x1000020 76; CHECK-NEXT: .long 0 # BTF_KIND_STRUCT(id = 4) 77; CHECK-NEXT: .long 67108866 # 0x4000002 78; CHECK-NEXT: .long 8 79; CHECK-NEXT: .long 17 80; CHECK-NEXT: .long 3 81; CHECK-NEXT: .long 0 # 0x0 82; CHECK-NEXT: .long 23 83; CHECK-NEXT: .long 5 84; CHECK-NEXT: .long 32 # 0x20 85; CHECK-NEXT: .long 0 # BTF_KIND_UNION(id = 5) 86; CHECK-NEXT: .long 83886082 # 0x5000002 87; CHECK-NEXT: .long 4 88; CHECK-NEXT: .long 27 89; CHECK-NEXT: .long 3 90; CHECK-NEXT: .long 0 # 0x0 91; CHECK-NEXT: .long 34 92; CHECK-NEXT: .long 3 93; CHECK-NEXT: .long 0 # 0x0 94; CHECK-NEXT: .long 0 # BTF_KIND_FUNC_PROTO(id = 6) 95; CHECK-NEXT: .long 218103809 # 0xd000001 96; CHECK-NEXT: .long 3 97; CHECK-NEXT: .long 41 98; CHECK-NEXT: .long 1 99; CHECK-NEXT: .long 45 # BTF_KIND_FUNC(id = 7) 100; CHECK-NEXT: .long 201326593 # 0xc000001 101; CHECK-NEXT: .long 6 102; CHECK-NEXT: .byte 0 # string offset=0 103; CHECK-NEXT: .ascii "sk_buff" # string offset=1 104; CHECK-NEXT: .byte 0 105; CHECK-NEXT: .byte 105 # string offset=9 106; CHECK-NEXT: .byte 0 107; CHECK-NEXT: .byte 117 # string offset=11 108; CHECK-NEXT: .byte 0 109; CHECK-NEXT: .ascii "int" # string offset=13 110; CHECK-NEXT: .byte 0 111; CHECK-NEXT: .ascii "netid" # string offset=17 112; CHECK-NEXT: .byte 0 113; CHECK-NEXT: .ascii "dev" # string offset=23 114; CHECK-NEXT: .byte 0 115; CHECK-NEXT: .ascii "dev_id" # string offset=27 116; CHECK-NEXT: .byte 0 117; CHECK-NEXT: .ascii "others" # string offset=34 118; CHECK-NEXT: .byte 0 119; CHECK-NEXT: .ascii "ctx" # string offset=41 120; CHECK-NEXT: .byte 0 121; CHECK-NEXT: .ascii "bpf_prog" # string offset=45 122; CHECK-NEXT: .byte 0 123; CHECK-NEXT: .ascii ".text" # string offset=54 124; CHECK-NEXT: .byte 0 125; CHECK-NEXT: .ascii "/tmp/home/yhs/work/tests/llvm/test.c" # string offset=60 126; CHECK-NEXT: .byte 0 127; CHECK-NEXT: .ascii "0:1:1:0" # string offset=97 128; CHECK-NEXT: .byte 0 129; CHECK-NEXT: .section .BTF.ext,"",@progbits 130; CHECK-NEXT: .short 60319 # 0xeb9f 131; CHECK-NEXT: .byte 1 132; CHECK-NEXT: .byte 0 133; CHECK-NEXT: .long 32 134; CHECK-NEXT: .long 0 135; CHECK-NEXT: .long 20 136; CHECK-NEXT: .long 20 137; CHECK-NEXT: .long {{[0-9]+}} 138; CHECK-NEXT: .long {{[0-9]+}} 139; CHECK-NEXT: .long 28 140; CHECK-NEXT: .long 8 # FuncInfo 141 142; CHECK: .long 16 # FieldReloc 143; CHECK-NEXT: .long 54 # Field reloc section string offset=54 144; CHECK-NEXT: .long 1 145; CHECK-NEXT: .long .Ltmp{{[0-9]+}} 146; CHECK-NEXT: .long 2 147; CHECK-NEXT: .long 97 148; CHECK-NEXT: .long 0 149 150; Function Attrs: argmemonly nounwind 151declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #1 152 153; Function Attrs: nounwind readnone 154declare %union.sk_buff* @llvm.preserve.union.access.index.p0s_union.sk_buffs.p0s_union.sk_buffs(%union.sk_buff*, i32 immarg) #2 155 156; Function Attrs: nounwind readnone 157declare %union.anon* @llvm.preserve.struct.access.index.p0s_union.anons.p0s_struct.anons(%struct.anon*, i32 immarg, i32 immarg) #2 158 159; Function Attrs: nounwind readnone 160declare %union.anon* @llvm.preserve.union.access.index.p0s_union.anons.p0s_union.anons(%union.anon*, i32 immarg) #2 161 162; Function Attrs: argmemonly nounwind 163declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #1 164 165; Function Attrs: nounwind readnone speculatable 166declare void @llvm.dbg.value(metadata, metadata, metadata) #3 167 168attributes #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" } 169attributes #1 = { argmemonly nounwind } 170attributes #2 = { nounwind readnone } 171attributes #3 = { nounwind readnone speculatable } 172attributes #4 = { nounwind } 173 174!llvm.dbg.cu = !{!0} 175!llvm.module.flags = !{!11, !12, !13} 176!llvm.ident = !{!14} 177 178!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) 179!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm") 180!2 = !{} 181!3 = !{!4} 182!4 = !DIGlobalVariableExpression(var: !5, expr: !DIExpression()) 183!5 = distinct !DIGlobalVariable(name: "bpf_probe_read", scope: !0, file: !1, line: 12, type: !6, isLocal: true, isDefinition: true) 184!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64) 185!7 = !DISubroutineType(types: !8) 186!8 = !{!9, !10, !9, !10} 187!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 188!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64) 189!11 = !{i32 2, !"Dwarf Version", i32 4} 190!12 = !{i32 2, !"Debug Info Version", i32 3} 191!13 = !{i32 1, !"wchar_size", i32 4} 192!14 = !{!"clang version 9.0.0 (trunk 360739) (llvm/trunk 360747)"} 193!15 = distinct !DISubprogram(name: "bpf_prog", scope: !1, file: !1, line: 15, type: !16, scopeLine: 15, flags: DIFlagPrototyped, isLocal: false, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !31) 194!16 = !DISubroutineType(types: !17) 195!17 = !{!9, !18} 196!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64) 197!19 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "sk_buff", file: !1, line: 1, size: 64, elements: !20) 198!20 = !{!21, !22} 199!21 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !19, file: !1, line: 2, baseType: !9, size: 32) 200!22 = !DIDerivedType(tag: DW_TAG_member, name: "u", scope: !19, file: !1, line: 9, baseType: !23, size: 64) 201!23 = distinct !DICompositeType(tag: DW_TAG_structure_type, scope: !19, file: !1, line: 3, size: 64, elements: !24) 202!24 = !{!25, !26} 203!25 = !DIDerivedType(tag: DW_TAG_member, name: "netid", scope: !23, file: !1, line: 4, baseType: !9, size: 32) 204!26 = !DIDerivedType(tag: DW_TAG_member, name: "dev", scope: !23, file: !1, line: 8, baseType: !27, size: 32, offset: 32) 205!27 = distinct !DICompositeType(tag: DW_TAG_union_type, scope: !23, file: !1, line: 5, size: 32, elements: !28) 206!28 = !{!29, !30} 207!29 = !DIDerivedType(tag: DW_TAG_member, name: "dev_id", scope: !27, file: !1, line: 6, baseType: !9, size: 32) 208!30 = !DIDerivedType(tag: DW_TAG_member, name: "others", scope: !27, file: !1, line: 7, baseType: !9, size: 32) 209!31 = !{!32, !33} 210!32 = !DILocalVariable(name: "ctx", arg: 1, scope: !15, file: !1, line: 15, type: !18) 211!33 = !DILocalVariable(name: "dev_id", scope: !15, file: !1, line: 16, type: !9) 212!34 = !DILocation(line: 0, scope: !15) 213!35 = !DILocation(line: 16, column: 3, scope: !15) 214!36 = !DILocation(line: 17, column: 40, scope: !15) 215!37 = !DILocation(line: 17, column: 3, scope: !15) 216!38 = !DILocation(line: 18, column: 10, scope: !15) 217!39 = !{!40, !40, i64 0} 218!40 = !{!"int", !41, i64 0} 219!41 = !{!"omnipotent char", !42, i64 0} 220!42 = !{!"Simple C/C++ TBAA"} 221!43 = !DILocation(line: 19, column: 1, scope: !15) 222!44 = !DILocation(line: 18, column: 3, scope: !15) 223