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

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 6 09:45:38 PDT 2025


================
@@ -672,16 +714,23 @@ void BTFDebug::visitStructType(const DICompositeType *CTy, bool IsStruct,
                                uint32_t &TypeId) {
   const DINodeArray Elements = CTy->getElements();
   uint32_t VLen = Elements.size();
+  // Variant parts have a discriminator. LLVM DI doesn't consider it as an
+  // element and instead keeps it as a separate reference. But we represent it
+  // as an element in BTF.
+  if (CTy->getTag() == dwarf::DW_TAG_variant_part)
+    VLen++;
----------------
eddyz87 wrote:

Discriminator's type is not guaranteed to be visited by `visitStructType`, please extend this logic to something like below:

```diff
@@ -717,8 +721,10 @@ void BTFDebug::visitStructType(const DICompositeType *CTy, bool IsStruct,
   // Variant parts have a discriminator. LLVM DI doesn't consider it as an
   // element and instead keeps it as a separate reference. But we represent it
   // as an element in BTF.
-  if (CTy->getTag() == dwarf::DW_TAG_variant_part)
+  if (CTy->getTag() == dwarf::DW_TAG_variant_part && CTy->getDiscriminator()) {
+    visitTypeEntry(CTy->getDiscriminator());
     VLen++;
+  }
   if (VLen > BTF::MAX_VLEN)
     return;
```

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


More information about the llvm-commits mailing list