128 lines · plain
1; RUN: opt -O2 -mtriple=bpf-pc-linux %s | llvm-dis > %t12; RUN: llc -o - %t1 | FileCheck %s3;4; Source:5; #pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)6; typedef union {7; struct {8; void *kernel;9; void *user;10; };11; unsigned is_kernel : 1;12; } sockptr_t;13; #pragma clang attribute pop14; void *foo(void);15; int test() {16; sockptr_t *arg = foo();17; return __builtin_preserve_field_info(arg->is_kernel, 1);18; }19; Compilation flag:20; clang -target bpf -O2 -S -emit-llvm -g -Xclang -disable-llvm-passes test.c21 22%union.sockptr_t = type { %struct.anon }23%struct.anon = type { ptr, ptr }24 25; Function Attrs: nounwind26define dso_local i32 @test() #0 !dbg !7 {27entry:28 %arg = alloca ptr, align 829 call void @llvm.lifetime.start.p0(i64 8, ptr %arg) #6, !dbg !2530 call void @llvm.dbg.declare(metadata ptr %arg, metadata !12, metadata !DIExpression()), !dbg !2631 %call = call ptr @foo(), !dbg !2732 store ptr %call, ptr %arg, align 8, !dbg !26, !tbaa !2833 %0 = load ptr, ptr %arg, align 8, !dbg !32, !tbaa !2834 %1 = call ptr @llvm.preserve.struct.access.index.p0.p0(ptr elementtype(%union.sockptr_t) %0, i32 0, i32 1), !dbg !33, !llvm.preserve.access.index !1535 %2 = call i32 @llvm.bpf.preserve.field.info.p0(ptr %1, i64 1), !dbg !3436 call void @llvm.lifetime.end.p0(i64 8, ptr %arg) #6, !dbg !3537 ret i32 %2, !dbg !3638}39 40; CHECK: .long 56 # BTF_KIND_TYPEDEF(id = 7)41; CHECK-NEXT: .long 134217728 # 0x800000042; CHECK-NEXT: .long 843; CHECK-NEXT: .long 0 # BTF_KIND_UNION(id = 8)44 45; CHECK: .ascii ".text" # string offset=1046; CHECK: .ascii "sockptr_t" # string offset=5647; CHECK: .ascii "0:1" # string offset=10148 49 50; CHECK: .long 16 # FieldReloc51; CHECK-NEXT: .long 10 # Field reloc section string offset=1052; CHECK-NEXT: .long 153; CHECK-NEXT: .long .Ltmp[[#]]54; CHECK-NEXT: .long 755; CHECK-NEXT: .long 10156; CHECK-NEXT: .long 157 58; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn59declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #160 61; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn62declare void @llvm.dbg.declare(metadata, metadata, metadata) #263 64declare !dbg !37 dso_local ptr @foo() #365 66; Function Attrs: nocallback nofree nosync nounwind readnone willreturn67declare ptr @llvm.preserve.struct.access.index.p0.p0(ptr, i32 immarg, i32 immarg) #468 69; Function Attrs: nounwind readnone70declare i32 @llvm.bpf.preserve.field.info.p0(ptr, i64 immarg) #571 72; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn73declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #174 75attributes #0 = { nounwind "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }76attributes #1 = { argmemonly nocallback nofree nosync nounwind willreturn }77attributes #2 = { nocallback nofree nosync nounwind readnone speculatable willreturn }78attributes #3 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }79attributes #4 = { nocallback nofree nosync nounwind readnone willreturn }80attributes #5 = { nounwind readnone }81attributes #6 = { nounwind }82 83!llvm.dbg.cu = !{!0}84!llvm.module.flags = !{!2, !3, !4, !5}85!llvm.ident = !{!6}86 87!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 15.0.0 (https://github.com/llvm/llvm-project.git 8c7d5118961e7ffc0304126ec2122d21e2eb1f79)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)88!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/test/anon", checksumkind: CSK_MD5, checksum: "2c5f698241a8b5ddf345a5743dfca258")89!2 = !{i32 7, !"Dwarf Version", i32 5}90!3 = !{i32 2, !"Debug Info Version", i32 3}91!4 = !{i32 1, !"wchar_size", i32 4}92!5 = !{i32 7, !"frame-pointer", i32 2}93!6 = !{!"clang version 15.0.0 (https://github.com/llvm/llvm-project.git 8c7d5118961e7ffc0304126ec2122d21e2eb1f79)"}94!7 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 11, type: !8, scopeLine: 11, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)95!8 = !DISubroutineType(types: !9)96!9 = !{!10}97!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)98!11 = !{!12}99!12 = !DILocalVariable(name: "arg", scope: !7, file: !1, line: 12, type: !13)100!13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64)101!14 = !DIDerivedType(tag: DW_TAG_typedef, name: "sockptr_t", file: !1, line: 8, baseType: !15)102!15 = distinct !DICompositeType(tag: DW_TAG_union_type, file: !1, line: 2, size: 128, elements: !16)103!16 = !{!17, !23}104!17 = !DIDerivedType(tag: DW_TAG_member, scope: !15, file: !1, line: 3, baseType: !18, size: 128)105!18 = distinct !DICompositeType(tag: DW_TAG_structure_type, scope: !15, file: !1, line: 3, size: 128, elements: !19)106!19 = !{!20, !22}107!20 = !DIDerivedType(tag: DW_TAG_member, name: "kernel", scope: !18, file: !1, line: 4, baseType: !21, size: 64)108!21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)109!22 = !DIDerivedType(tag: DW_TAG_member, name: "user", scope: !18, file: !1, line: 5, baseType: !21, size: 64, offset: 64)110!23 = !DIDerivedType(tag: DW_TAG_member, name: "is_kernel", scope: !15, file: !1, line: 7, baseType: !24, size: 1, flags: DIFlagBitField, extraData: i64 0)111!24 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)112!25 = !DILocation(line: 12, column: 3, scope: !7)113!26 = !DILocation(line: 12, column: 14, scope: !7)114!27 = !DILocation(line: 12, column: 20, scope: !7)115!28 = !{!29, !29, i64 0}116!29 = !{!"any pointer", !30, i64 0}117!30 = !{!"omnipotent char", !31, i64 0}118!31 = !{!"Simple C/C++ TBAA"}119!32 = !DILocation(line: 13, column: 40, scope: !7)120!33 = !DILocation(line: 13, column: 45, scope: !7)121!34 = !DILocation(line: 13, column: 10, scope: !7)122!35 = !DILocation(line: 14, column: 1, scope: !7)123!36 = !DILocation(line: 13, column: 3, scope: !7)124!37 = !DISubprogram(name: "foo", scope: !1, file: !1, line: 10, type: !38, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !40)125!38 = !DISubroutineType(types: !39)126!39 = !{!21}127!40 = !{}128