1; RUN: opt -O2 -mtriple=bpf-pc-linux %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; 5; Source code: 6; static int (*bpf_log)(unsigned long tid, ptr data, int data_size) = (ptr)999; 7; struct { 8; char f1[100]; 9; typeof(3) f2; 10; } tmp__abc = {1, 3}; 11; void prog1() { 12; bpf_log(__builtin_btf_type_id(tmp__abc, 0), &tmp__abc, sizeof(tmp__abc)); 13; } 14; void prog2() { 15; bpf_log(__builtin_btf_type_id(&tmp__abc, 0), &tmp__abc, sizeof(tmp__abc)); 16; } 17; void prog3() { 18; bpf_log(__builtin_btf_type_id(tmp__abc.f1[3], 1), &tmp__abc, sizeof(tmp__abc)); 19; } 20; Compilation flag: 21; clang -target bpf -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c 22 23@tmp__abc = dso_local global { <{ i8, i8, [98 x i8] }>, i32 } { <{ i8, i8, [98 x i8] }> <{ i8 1, i8 3, [98 x i8] zeroinitializer }>, i32 0 }, align 4, !dbg !0 24@bpf_log = internal global ptr inttoptr (i64 999 to ptr), align 8, !dbg !17 25 26; Function Attrs: nounwind 27define dso_local void @prog1() #0 !dbg !28 { 28entry: 29 %0 = load ptr, ptr @bpf_log, align 8, !dbg !31, !tbaa !32 30 %1 = call i64 @llvm.bpf.btf.type.id(i32 0, i64 0), !dbg !36, !llvm.preserve.access.index !7 31 %call = call i32 %0(i64 %1, ptr @tmp__abc, i32 104), !dbg !31 32 ret void, !dbg !37 33} 34 35; Function Attrs: nounwind readnone 36declare i64 @llvm.bpf.btf.type.id(i32, i64) #1 37 38; Function Attrs: nounwind 39define dso_local void @prog2() #0 !dbg !38 { 40entry: 41 %0 = load ptr, ptr @bpf_log, align 8, !dbg !39, !tbaa !32 42 %1 = call i64 @llvm.bpf.btf.type.id(i32 1, i64 0), !dbg !40, !llvm.preserve.access.index !6 43 %call = call i32 %0(i64 %1, ptr @tmp__abc, i32 104), !dbg !39 44 ret void, !dbg !41 45} 46 47; Function Attrs: nounwind 48define dso_local void @prog3() #0 !dbg !42 { 49entry: 50 %0 = load ptr, ptr @bpf_log, align 8, !dbg !43, !tbaa !32 51 %1 = call i64 @llvm.bpf.btf.type.id(i32 2, i64 1), !dbg !44, !llvm.preserve.access.index !11 52 %call = call i32 %0(i64 %1, ptr @tmp__abc, i32 104), !dbg !43 53 ret void, !dbg !45 54} 55 56; CHECK-LABEL: prog1 57; CHECK: r1 = 3 ll 58; CHECK-LABEL: prog2 59; CHECK: r1 = 10 ll 60; CHECK-LABEL: prog3 61; CHECK: r1 = 4 ll 62 63; CHECK: .long 0 # BTF_KIND_STRUCT(id = 3) 64; CHECK-NEXT: .long 67108866 # 0x4000002 65; CHECK-NEXT: .long 104 66; CHECK-NEXT: .long 13 67; CHECK-NEXT: .long 5 68; CHECK-NEXT: .long 0 # 0x0 69; CHECK-NEXT: .long 16 70; CHECK-NEXT: .long 7 71; CHECK-NEXT: .long 800 # 0x320 72; CHECK: .long 19 # BTF_KIND_INT(id = 4) 73; CHECK: .long 0 # BTF_KIND_PTR(id = 10) 74; CHECK-NEXT: .long 33554432 # 0x2000000 75; CHECK-NEXT: .long 3 76 77; CHECK: .ascii ".text" # string offset=7 78; CHECK: .ascii "f1" # string offset=13 79; CHECK: .ascii "f2" # string offset=16 80; CHECK: .ascii "char" # string offset=19 81; CHECK: .byte 48 # string offset=48 82 83; CHECK: .long 16 # FieldReloc 84; CHECK-NEXT: .long 7 # Field reloc section string offset=7 85; CHECK-NEXT: .long 3 86; CHECK-NEXT: .long .Ltmp{{[0-9]+}} 87; CHECK-NEXT: .long 3 88; CHECK-NEXT: .long 48 89; CHECK-NEXT: .long 6 90; CHECK-NEXT: .long .Ltmp{{[0-9]+}} 91; CHECK-NEXT: .long 10 92; CHECK-NEXT: .long 48 93; CHECK-NEXT: .long 6 94; CHECK-NEXT: .long .Ltmp{{[0-9]+}} 95; CHECK-NEXT: .long 4 96; CHECK-NEXT: .long 48 97; CHECK-NEXT: .long 7 98 99attributes #0 = { nounwind "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"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } 100attributes #1 = { nounwind readnone } 101 102!llvm.dbg.cu = !{!2} 103!llvm.module.flags = !{!24, !25, !26} 104!llvm.ident = !{!27} 105 106!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 107!1 = distinct !DIGlobalVariable(name: "tmp__abc", scope: !2, file: !3, line: 5, type: !7, isLocal: false, isDefinition: true) 108!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 12.0.0 (https://github.com/llvm/llvm-project.git 630c2da0e967e27e2a4c678dfc6e452a74141880)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, retainedTypes: !5, globals: !16, splitDebugInlining: false, nameTableKind: None) 109!3 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core") 110!4 = !{} 111!5 = !{!6, !11} 112!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64) 113!7 = distinct !DICompositeType(tag: DW_TAG_structure_type, file: !3, line: 2, size: 832, elements: !8) 114!8 = !{!9, !14} 115!9 = !DIDerivedType(tag: DW_TAG_member, name: "f1", scope: !7, file: !3, line: 3, baseType: !10, size: 800) 116!10 = !DICompositeType(tag: DW_TAG_array_type, baseType: !11, size: 800, elements: !12) 117!11 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) 118!12 = !{!13} 119!13 = !DISubrange(count: 100) 120!14 = !DIDerivedType(tag: DW_TAG_member, name: "f2", scope: !7, file: !3, line: 4, baseType: !15, size: 32, offset: 800) 121!15 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 122!16 = !{!0, !17} 123!17 = !DIGlobalVariableExpression(var: !18, expr: !DIExpression()) 124!18 = distinct !DIGlobalVariable(name: "bpf_log", scope: !2, file: !3, line: 1, type: !19, isLocal: true, isDefinition: true) 125!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64) 126!20 = !DISubroutineType(types: !21) 127!21 = !{!15, !22, !23, !15} 128!22 = !DIBasicType(name: "long unsigned int", size: 64, encoding: DW_ATE_unsigned) 129!23 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64) 130!24 = !{i32 7, !"Dwarf Version", i32 4} 131!25 = !{i32 2, !"Debug Info Version", i32 3} 132!26 = !{i32 1, !"wchar_size", i32 4} 133!27 = !{!"clang version 12.0.0 (https://github.com/llvm/llvm-project.git 630c2da0e967e27e2a4c678dfc6e452a74141880)"} 134!28 = distinct !DISubprogram(name: "prog1", scope: !3, file: !3, line: 6, type: !29, scopeLine: 6, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !4) 135!29 = !DISubroutineType(types: !30) 136!30 = !{null} 137!31 = !DILocation(line: 7, column: 3, scope: !28) 138!32 = !{!33, !33, i64 0} 139!33 = !{!"any pointer", !34, i64 0} 140!34 = !{!"omnipotent char", !35, i64 0} 141!35 = !{!"Simple C/C++ TBAA"} 142!36 = !DILocation(line: 7, column: 11, scope: !28) 143!37 = !DILocation(line: 8, column: 1, scope: !28) 144!38 = distinct !DISubprogram(name: "prog2", scope: !3, file: !3, line: 9, type: !29, scopeLine: 9, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !4) 145!39 = !DILocation(line: 10, column: 3, scope: !38) 146!40 = !DILocation(line: 10, column: 11, scope: !38) 147!41 = !DILocation(line: 11, column: 1, scope: !38) 148!42 = distinct !DISubprogram(name: "prog3", scope: !3, file: !3, line: 12, type: !29, scopeLine: 12, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !4) 149!43 = !DILocation(line: 13, column: 3, scope: !42) 150!44 = !DILocation(line: 13, column: 11, scope: !42) 151!45 = !DILocation(line: 14, column: 1, scope: !42) 152