[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
================
@@ -301,21 +303,61 @@ void BTFTypeStruct::completeType(BTFDebug &BDebug) {
BTFType.NameOff = BDebug.addString(STy->getName());
+ uint64_t InitialOffset = 0;
+ if (STy->getTag() == dwarf::DW_TAG_variant_part) {
+ // Variant parts have a discriminator, which has its own memory location at
+ // the beginning, and variants, which share the memory location afterwards.
+ // LLVM DI doesn't consider discriminator as an element and instead keeps
+ // it as a separate reference.
+ // To keep BTF simple, let's represent the structure as an union with
+ // discriminator as the first element and apply offsets to the other
+ // elements.
+ struct BTF::BTFMember Discriminator;
+ const auto *DDTy = STy->getDiscriminator();
----------------
eddyz87 wrote:
Discriminator is not guaranteed to exist in general case, here and in other places, please check it for NULL.
https://github.com/llvm/llvm-project/pull/155783
More information about the llvm-commits
mailing list