Skip to content

Commit 3fa946a

Browse files
authored
[DI] Have createClassType create a class type. (#102624)
I was wondering why my use of createClassType was generating structure reccords, and it turns out the code is wrong (or for some reason i don't understand the intended use of the API). clang itself does not use that part of the API, so this flew under the radar.
1 parent a9636b7 commit 3fa946a

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

llvm/lib/IR/DIBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ DICompositeType *DIBuilder::createClassType(
509509
"createClassType should be called with a valid Context");
510510

511511
auto *R = DICompositeType::get(
512-
VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber,
512+
VMContext, dwarf::DW_TAG_class_type, Name, File, LineNumber,
513513
getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits,
514514
OffsetInBits, Flags, Elements, RunTimeLang, VTableHolder,
515515
cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier);

llvm/unittests/IR/DebugInfoTest.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,4 +1244,37 @@ TEST(DIBuilder, HashingDISubprogram) {
12441244
EXPECT_EQ(HashDefinition, HashDefinitionAfter);
12451245
}
12461246

1247+
TEST(DIBuilder, CompositeTypes) {
1248+
LLVMContext Ctx;
1249+
std::unique_ptr<Module> M = std::make_unique<Module>("MyModule", Ctx);
1250+
DIBuilder DIB(*M);
1251+
1252+
DIFile *F = DIB.createFile("main.c", "/");
1253+
DICompileUnit *CU =
1254+
DIB.createCompileUnit(dwarf::DW_LANG_C, F, "Test", false, "", 0);
1255+
1256+
DICompositeType *Class =
1257+
DIB.createClassType(CU, "MyClass", F, 0, 8, 8, 0, {}, nullptr, {}, 0,
1258+
nullptr, nullptr, "ClassUniqueIdentifier");
1259+
EXPECT_EQ(Class->getTag(), dwarf::DW_TAG_class_type);
1260+
1261+
DICompositeType *Struct = DIB.createStructType(
1262+
CU, "MyStruct", F, 0, 8, 8, {}, {}, {}, 0, {}, "StructUniqueIdentifier");
1263+
EXPECT_EQ(Struct->getTag(), dwarf::DW_TAG_structure_type);
1264+
1265+
DICompositeType *Union = DIB.createUnionType(CU, "MyUnion", F, 0, 8, 8, {},
1266+
{}, 0, "UnionUniqueIdentifier");
1267+
EXPECT_EQ(Union->getTag(), dwarf::DW_TAG_union_type);
1268+
1269+
DICompositeType *Array = DIB.createArrayType(8, 8, nullptr, {});
1270+
EXPECT_EQ(Array->getTag(), dwarf::DW_TAG_array_type);
1271+
1272+
DICompositeType *Vector = DIB.createVectorType(8, 8, nullptr, {});
1273+
EXPECT_EQ(Vector->getTag(), dwarf::DW_TAG_array_type);
1274+
1275+
DICompositeType *Enum = DIB.createEnumerationType(
1276+
CU, "MyEnum", F, 0, 8, 8, {}, nullptr, 0, "EnumUniqueIdentifier");
1277+
EXPECT_EQ(Enum->getTag(), dwarf::DW_TAG_enumeration_type);
1278+
}
1279+
12471280
} // end namespace

0 commit comments

Comments
 (0)