[llvm] 040f5ee - Add flags check to createVariantMemberType (#139261)

via llvm-commits llvm-commits at lists.llvm.org
Thu May 29 10:26:09 PDT 2025


Author: Tom Tromey
Date: 2025-05-29T10:26:06-07:00
New Revision: 040f5ee41014724af7dc4941ff9f4223b4db67d4

URL: https://github.com/llvm/llvm-project/commit/040f5ee41014724af7dc4941ff9f4223b4db67d4
DIFF: https://github.com/llvm/llvm-project/commit/040f5ee41014724af7dc4941ff9f4223b4db67d4.diff

LOG: Add flags check to createVariantMemberType (#139261)

I noticed that DIDerivedType overloads the "ExtraData" member depending
on the precise type being implemented. A variant part uses this to store
the discriminant (a reference to another member), but a bit field uses
it to store the storage offset.

This patch changes createVariantMemberType to ensure that the
FlagBitField is not used when creating a variant part. If this flag is
used, the ExtraData field would be erroneously used in two different
ways.

The patch also updates a comment in DIDerivedType to list a couple more
cases.

Added: 
    

Modified: 
    llvm/include/llvm/IR/DebugInfoMetadata.h
    llvm/lib/IR/DIBuilder.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h
index d82c69aebb026..8531424cc136f 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -1253,7 +1253,8 @@ class DIDerivedType : public DIType {
   ///
   /// Class type for pointer-to-members, objective-c property node for ivars,
   /// global constant wrapper for static members, virtual base pointer offset
-  /// for inheritance, or a tuple of template parameters for template aliases.
+  /// for inheritance, a tuple of template parameters for template aliases,
+  /// discriminant for a variant, or storage offset for a bit field.
   ///
   /// TODO: Separate out types that need this extra operand: pointer-to-member
   /// types and member fields (static members and ivars).

diff  --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 90da9f3acfe57..7d611506e18e0 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -438,6 +438,9 @@ DIDerivedType *DIBuilder::createVariantMemberType(
     DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
     uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
     Constant *Discriminant, DINode::DIFlags Flags, DIType *Ty) {
+  // "ExtraData" is overloaded for bit fields and for variants, so
+  // make sure to disallow this.
+  assert((Flags & DINode::FlagBitField) == 0);
   return DIDerivedType::get(
       VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
       getNonCompileUnitScope(Scope), Ty, SizeInBits, AlignInBits, OffsetInBits,


        


More information about the llvm-commits mailing list