1; RUN: opt -O2 -mtriple=bpf-pc-linux %s | llvm-dis > %t1 2; RUN: llc -filetype=asm -o - %t1 | FileCheck %s 3; RUN: llc -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck %s 4; Source code: 5; #define BPF_FIELD_EXISTS 2 6; unsigned test1() { 7; struct t { 8; int val; 9; } bar; 10; return __builtin_preserve_field_info((&bar)[1], BPF_FIELD_EXISTS); 11; } 12; Compilation flag: 13; clang -target bpf -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c 14 15%struct.t = type { i32 } 16 17; Function Attrs: nounwind 18define dso_local i32 @test1() #0 !dbg !6 { 19entry: 20 %bar = alloca %struct.t, align 4 21 call void @llvm.lifetime.start.p0(i64 4, ptr %bar) #5, !dbg !20 22 call void @llvm.dbg.declare(metadata ptr %bar, metadata !11, metadata !DIExpression()), !dbg !21 23 %0 = call ptr @llvm.preserve.array.access.index.p0.ts.p0.ts(ptr elementtype(%struct.t) %bar, i32 0, i32 1), !dbg !22, !llvm.preserve.access.index !4 24 %1 = call i32 @llvm.bpf.preserve.field.info.p0.ts(ptr %0, i64 2), !dbg !23 25 call void @llvm.lifetime.end.p0(i64 4, ptr %bar) #5, !dbg !24 26 ret i32 %1, !dbg !25 27} 28 29; CHECK: r0 = 1 30; CHECK-NEXT: exit 31 32; CHECK: .long 26 # BTF_KIND_STRUCT(id = 4) 33; CHECK-NEXT: .long 67108865 # 0x4000001 34; CHECK-NEXT: .long 4 35; CHECK-NEXT: .long 28 36; CHECK-NEXT: .long 5 37; CHECK-NEXT: .long 0 # 0x0 38; CHECK-NEXT: .long 32 # BTF_KIND_INT(id = 5) 39; CHECK-NEXT: .long 16777216 # 0x1000000 40; CHECK-NEXT: .long 4 41; CHECK-NEXT: .long 16777248 # 0x1000020 42 43; CHECK: .byte 116 # string offset=26 44; CHECK: .ascii "val" # string offset=28 45; CHECK: .ascii "int" # string offset=32 46; CHECK: .byte 49 # string offset=36 47 48; CHECK: .long 16 # FieldReloc 49; CHECK-NEXT: .long {{[0-9]+}} # Field reloc section string 50; CHECK-NEXT: .long 1 51; CHECK-NEXT: .long .Ltmp{{[0-9]+}} 52; CHECK-NEXT: .long 4 53; CHECK-NEXT: .long 36 54; CHECK-NEXT: .long 2 55 56; Function Attrs: argmemonly nofree nosync nounwind willreturn 57declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1 58 59; Function Attrs: nofree nosync nounwind readnone speculatable willreturn 60declare void @llvm.dbg.declare(metadata, metadata, metadata) #2 61 62; Function Attrs: nofree nosync nounwind readnone willreturn 63declare ptr @llvm.preserve.array.access.index.p0.ts.p0.ts(ptr, i32 immarg, i32 immarg) #3 64 65; Function Attrs: nounwind readnone 66declare i32 @llvm.bpf.preserve.field.info.p0.ts(ptr, i64 immarg) #4 67 68; Function Attrs: argmemonly nofree nosync nounwind willreturn 69declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1 70 71attributes #0 = { nounwind "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } 72attributes #1 = { argmemonly nofree nosync nounwind willreturn } 73attributes #2 = { nofree nosync nounwind readnone speculatable willreturn } 74attributes #3 = { nofree nosync nounwind readnone willreturn } 75attributes #4 = { nounwind readnone } 76attributes #5 = { nounwind } 77 78!llvm.dbg.cu = !{!0} 79!llvm.module.flags = !{!15, !16, !17, !18} 80!llvm.ident = !{!19} 81 82!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 13.0.0 (https://github.com/llvm/llvm-project.git 2e0ee68dc85c0a2b7e65e489a60ab363393b06a8)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, splitDebugInlining: false, nameTableKind: None) 83!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core") 84!2 = !{} 85!3 = !{!4} 86!4 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64) 87!5 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t", scope: !6, file: !1, line: 3, size: 32, elements: !12) 88!6 = distinct !DISubprogram(name: "test1", scope: !1, file: !1, line: 2, type: !7, scopeLine: 2, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !10) 89!7 = !DISubroutineType(types: !8) 90!8 = !{!9} 91!9 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned) 92!10 = !{!11} 93!11 = !DILocalVariable(name: "bar", scope: !6, file: !1, line: 5, type: !5) 94!12 = !{!13} 95!13 = !DIDerivedType(tag: DW_TAG_member, name: "val", scope: !5, file: !1, line: 4, baseType: !14, size: 32) 96!14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 97!15 = !{i32 7, !"Dwarf Version", i32 4} 98!16 = !{i32 2, !"Debug Info Version", i32 3} 99!17 = !{i32 1, !"wchar_size", i32 4} 100!18 = !{i32 7, !"frame-pointer", i32 2} 101!19 = !{!"clang version 13.0.0 (https://github.com/llvm/llvm-project.git 2e0ee68dc85c0a2b7e65e489a60ab363393b06a8)"} 102!20 = !DILocation(line: 3, column: 3, scope: !6) 103!21 = !DILocation(line: 5, column: 5, scope: !6) 104!22 = !DILocation(line: 6, column: 40, scope: !6) 105!23 = !DILocation(line: 6, column: 10, scope: !6) 106!24 = !DILocation(line: 7, column: 1, scope: !6) 107!25 = !DILocation(line: 6, column: 3, scope: !6) 108