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

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 17 12:19:57 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:

I checked the `getDiscriminator()` implementation, and it seem to boil down to a static offset computation relative to `this`, so should be cheap (and hoisted by compiler?).

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


More information about the llvm-commits mailing list