Skip to content

Commit b4e8e4a

Browse files
tromeysvkeerthy
authored andcommitted
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.
1 parent 2a77f50 commit b4e8e4a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,8 @@ class DIDerivedType : public DIType {
12531253
///
12541254
/// Class type for pointer-to-members, objective-c property node for ivars,
12551255
/// global constant wrapper for static members, virtual base pointer offset
1256-
/// for inheritance, or a tuple of template parameters for template aliases.
1256+
/// for inheritance, a tuple of template parameters for template aliases,
1257+
/// discriminant for a variant, or storage offset for a bit field.
12571258
///
12581259
/// TODO: Separate out types that need this extra operand: pointer-to-member
12591260
/// types and member fields (static members and ivars).

llvm/lib/IR/DIBuilder.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ DIDerivedType *DIBuilder::createVariantMemberType(
438438
DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
439439
uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits,
440440
Constant *Discriminant, DINode::DIFlags Flags, DIType *Ty) {
441+
// "ExtraData" is overloaded for bit fields and for variants, so
442+
// make sure to disallow this.
443+
assert((Flags & DINode::FlagBitField) == 0);
441444
return DIDerivedType::get(
442445
VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
443446
getNonCompileUnitScope(Scope), Ty, SizeInBits, AlignInBits, OffsetInBits,

0 commit comments

Comments
 (0)