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

Michal R via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 1 07:13:02 PDT 2025


================
@@ -696,10 +710,14 @@ void BTFDebug::visitStructType(const DICompositeType *CTy, bool IsStruct,
   // Visit all struct members.
   int FieldNo = 0;
   for (const auto *Element : Elements) {
-    const auto Elem = cast<DIDerivedType>(Element);
-    visitTypeEntry(Elem);
-    processDeclAnnotations(Elem->getAnnotations(), TypeId, FieldNo);
-    FieldNo++;
+    if (const auto *Elem = dyn_cast<DIDerivedType>(Element)) {
----------------
vadorovsky wrote:

A `switch` statement makes it way cleaner, thank you for the suggestion~

I'm not sure what do you mean by an artificial field, but I think it's already there. The BTF of the "outer" struct looks like:

```
[1] STRUCT 'MyEnum' size=32 vlen=1
        '(anon)' type_id=2 bits_offset=0
```

So it has one anonymous field, of the variant part type:

```
[2] UNION '(anon)' size=32 vlen=2
        'First' type_id=3 bits_offset=0
        'Second' type_id=8 bits_offset=0
```

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


More information about the llvm-commits mailing list