[llvm] [BPF] Support for `DW_TAG_variant_part` in BTF generation (PR #155783)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 9 09:54:47 PDT 2025


eddyz87 wrote:

> > Do you plan to wrap this up?
> 
> I do, but I'm blocked by Rust which is emitting `undef` for all static variable definitions. Because of that, there is no way to make the CI happy with the IR test I added. Still trying to figure out a proper fix on Rust's side. If you prefer, I can close or mark this PR as draft until I sort it out.

But we know how rust represents the enum, you don't need rust to wrap up the test case. E.g. the IR below is all you need. It can even be cleaned up a bit.

```
$ cat test-debug-info.rs 
pub enum Adt {
    First { a: u32, b: i32 },
    Second(u32, i32),
}

pub static X: Adt = Adt::First{a:0, b:0};

$ rustc --emit=llvm-ir -C debuginfo=full --crate-type=lib -o - test-debug-info.rs 
; ModuleID = 'test_debug_info.bfdfecb05037b21e-cgu.0'
source_filename = "test_debug_info.bfdfecb05037b21e-cgu.0"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@_ZN15test_debug_info1X17h1cd60cbc8df4384cE = constant [12 x i8] zeroinitializer, align 4, !dbg !0

!llvm.module.flags = !{!23, !24, !25, !26}
!llvm.ident = !{!27}
!llvm.dbg.cu = !{!28}

!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
!1 = distinct !DIGlobalVariable(name: "X", linkageName: "_ZN15test_debug_info1X17h1cd60cbc8df4384cE", scope: !2, file: !3, line: 6, type: !4, isLocal: false, isDefinition: true, align: 32)
!2 = !DINamespace(name: "test_debug_info", scope: null)
!3 = !DIFile(filename: "test-debug-info.rs", directory: "/home/ezingerman/tmp", checksumkind: CSK_MD5, checksum: "d031470f0fcafae0cde20cea6e49f258")
!4 = !DICompositeType(tag: DW_TAG_structure_type, name: "Adt", scope: !2, file: !5, size: 96, align: 32, flags: DIFlagPublic, elements: !6, templateParams: !16, identifier: "b82d4441ddd9815f702f04ccb4300dfa")
!5 = !DIFile(filename: "<unknown>", directory: "")
!6 = !{!7}
!7 = !DICompositeType(tag: DW_TAG_variant_part, scope: !4, file: !5, size: 96, align: 32, elements: !8, templateParams: !16, identifier: "7cc4d1a13945d2033b3024c6d22bc7f3", discriminator: !22)
!8 = !{!9, !17}
!9 = !DIDerivedType(tag: DW_TAG_member, name: "First", scope: !7, file: !5, baseType: !10, size: 96, align: 32, extraData: i32 0)
!10 = !DICompositeType(tag: DW_TAG_structure_type, name: "First", scope: !4, file: !5, size: 96, align: 32, flags: DIFlagPublic, elements: !11, templateParams: !16, identifier: "3be91d17592010323b31ce88a6234f5c")
!11 = !{!12, !14}
!12 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !10, file: !5, baseType: !13, size: 32, align: 32, offset: 32, flags: DIFlagPublic)
!13 = !DIBasicType(name: "u32", size: 32, encoding: DW_ATE_unsigned)
!14 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !10, file: !5, baseType: !15, size: 32, align: 32, offset: 64, flags: DIFlagPublic)
!15 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed)
!16 = !{}
!17 = !DIDerivedType(tag: DW_TAG_member, name: "Second", scope: !7, file: !5, baseType: !18, size: 96, align: 32, extraData: i32 1)
!18 = !DICompositeType(tag: DW_TAG_structure_type, name: "Second", scope: !4, file: !5, size: 96, align: 32, flags: DIFlagPublic, elements: !19, templateParams: !16, identifier: "734c122892f88e54fc2cbc5b90961e52")
!19 = !{!20, !21}
!20 = !DIDerivedType(tag: DW_TAG_member, name: "__0", scope: !18, file: !5, baseType: !13, size: 32, align: 32, offset: 32, flags: DIFlagPublic)
!21 = !DIDerivedType(tag: DW_TAG_member, name: "__1", scope: !18, file: !5, baseType: !15, size: 32, align: 32, offset: 64, flags: DIFlagPublic)
!22 = !DIDerivedType(tag: DW_TAG_member, scope: !4, file: !5, baseType: !13, size: 32, align: 32, flags: DIFlagArtificial)
!23 = !{i32 8, !"PIC Level", i32 2}
!24 = !{i32 2, !"RtLibUseGOT", i32 1}
!25 = !{i32 7, !"Dwarf Version", i32 4}
!26 = !{i32 2, !"Debug Info Version", i32 3}
!27 = !{!"rustc version 1.88.0 (6b00bc388 2025-06-23) (Red Hat 1.88.0-1.el9)"}
!28 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !29, producer: "clang LLVM (rustc version 1.88.0 (6b00bc388 2025-06-23) (Red Hat 1.88.0-1.el9))", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !30, splitDebugInlining: false, nameTableKind: None)
!29 = !DIFile(filename: "test-debug-info.rs/@/test_debug_info.bfdfecb05037b21e-cgu.0", directory: "/home/ezingerman/tmp")
!30 = !{!0}
```

https://github.com/llvm/llvm-project/pull/155783


More information about the llvm-commits mailing list