Skip to content

[NFC] Adapt unit tests to new num_extra_inhabitants field #7662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions llvm/unittests/IR/DebugTypeODRUniquingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ TEST(DebugTypeODRUniquingTest, getODRType) {
// Without a type map, this should return null.
EXPECT_FALSE(DICompositeType::getODRType(
Context, UUID, dwarf::DW_TAG_class_type, nullptr, nullptr, 0, nullptr,
nullptr, 0, 0, 0, DINode::FlagZero, nullptr, 0, nullptr, nullptr, nullptr,
nullptr, 0, 0, 0, 0, DINode::FlagZero, nullptr, 0, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr));

// Enable the mapping. There still shouldn't be a type.
Expand All @@ -40,7 +40,7 @@ TEST(DebugTypeODRUniquingTest, getODRType) {
// Create some ODR-uniqued type.
auto &CT = *DICompositeType::getODRType(
Context, UUID, dwarf::DW_TAG_class_type, nullptr, nullptr, 0, nullptr,
nullptr, 0, 0, 0, DINode::FlagZero, nullptr, 0, nullptr, nullptr, nullptr,
nullptr, 0, 0, 0, 0, DINode::FlagZero, nullptr, 0, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr);
EXPECT_EQ(UUID.getString(), CT.getIdentifier());

Expand All @@ -49,13 +49,13 @@ TEST(DebugTypeODRUniquingTest, getODRType) {
EXPECT_EQ(&CT,
DICompositeType::getODRType(
Context, UUID, dwarf::DW_TAG_class_type, nullptr, nullptr, 0,
nullptr, nullptr, 0, 0, 0, DINode::FlagZero, nullptr, 0,
nullptr, nullptr, 0, 0, 0, 0, DINode::FlagZero, nullptr, 0,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr));
EXPECT_EQ(&CT, DICompositeType::getODRType(
Context, UUID, dwarf::DW_TAG_class_type,
MDString::get(Context, "name"), nullptr, 0, nullptr,
nullptr, 0, 0, 0, DINode::FlagZero, nullptr, 0, nullptr,
nullptr, 0, 0, 0, 0, DINode::FlagZero, nullptr, 0, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr));

Expand All @@ -76,41 +76,41 @@ TEST(DebugTypeODRUniquingTest, buildODRType) {
MDString &UUID = *MDString::get(Context, "Type");
auto &CT = *DICompositeType::buildODRType(
Context, UUID, dwarf::DW_TAG_class_type, nullptr, nullptr, 0, nullptr,
nullptr, 0, 0, 0, DINode::FlagFwdDecl, nullptr, 0, nullptr, nullptr,
nullptr, 0, 0, 0, 0, DINode::FlagFwdDecl, nullptr, 0, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
EXPECT_EQ(&CT, DICompositeType::getODRTypeIfExists(Context, UUID));
EXPECT_EQ(dwarf::DW_TAG_class_type, CT.getTag());

// Update with another forward decl. This should be a no-op.
EXPECT_EQ(&CT, DICompositeType::buildODRType(
Context, UUID, dwarf::DW_TAG_class_type, nullptr, nullptr,
0, nullptr, nullptr, 0, 0, 0, DINode::FlagFwdDecl, nullptr,
0, nullptr, nullptr, 0, 0, 0, 0, DINode::FlagFwdDecl, nullptr,
0, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr));

EXPECT_FALSE(DICompositeType::buildODRType(
Context, UUID, dwarf::DW_TAG_structure_type, nullptr, nullptr, 0, nullptr,
nullptr, 0, 0, 0, DINode::FlagFwdDecl, nullptr, 0, nullptr, nullptr,
nullptr, 0, 0, 0, 0, DINode::FlagFwdDecl, nullptr, 0, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr));

// Update with a definition. This time we should see a change.
EXPECT_EQ(&CT, DICompositeType::buildODRType(
Context, UUID, dwarf::DW_TAG_class_type, nullptr, nullptr,
0, nullptr, nullptr, 0, 0, 0, DINode::FlagZero, nullptr, 0,
0, nullptr, nullptr, 0, 0, 0, 0, DINode::FlagZero, nullptr, 0,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr));
EXPECT_FALSE(CT.isForwardDecl());

// Further updates should be ignored.
EXPECT_EQ(&CT, DICompositeType::buildODRType(
Context, UUID, dwarf::DW_TAG_class_type, nullptr, nullptr,
0, nullptr, nullptr, 0, 0, 0, DINode::FlagFwdDecl, nullptr,
0, nullptr, nullptr, 0, 0, 0, 0, DINode::FlagFwdDecl, nullptr,
0, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr));
EXPECT_FALSE(CT.isForwardDecl());
EXPECT_EQ(&CT, DICompositeType::buildODRType(
Context, UUID, dwarf::DW_TAG_class_type, nullptr, nullptr,
111u, nullptr, nullptr, 0, 0, 0, DINode::FlagZero, nullptr,
111u, nullptr, nullptr, 0, 0, 0, 0, DINode::FlagZero, nullptr,
0, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr));
EXPECT_NE(111u, CT.getLine());
Expand All @@ -123,7 +123,7 @@ TEST(DebugTypeODRUniquingTest, buildODRTypeFields) {
// Build an ODR type that's a forward decl with no other fields set.
MDString &UUID = *MDString::get(Context, "UUID");
auto &CT = *DICompositeType::buildODRType(
Context, UUID, 0, nullptr, nullptr, 0, nullptr, nullptr, 0, 0, 0,
Context, UUID, 0, nullptr, nullptr, 0, nullptr, nullptr, 0, 0, 0, 0,
DINode::FlagFwdDecl, nullptr, 0, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr);

Expand All @@ -141,6 +141,7 @@ TEST(DebugTypeODRUniquingTest, buildODRTypeFields) {
DO_FOR_FIELD(SizeInBits) \
DO_FOR_FIELD(AlignInBits) \
DO_FOR_FIELD(OffsetInBits) \
DO_FOR_FIELD(NumExtraInhabitants) \
DO_FOR_FIELD(RuntimeLang)

// Create all the fields.
Expand All @@ -153,12 +154,12 @@ TEST(DebugTypeODRUniquingTest, buildODRTypeFields) {
#undef DO_FOR_FIELD

// Replace all the fields with new values that are distinct from each other.
EXPECT_EQ(&CT,
DICompositeType::buildODRType(
Context, UUID, 0, Name, File, Line, Scope, BaseType, SizeInBits,
AlignInBits, OffsetInBits, DINode::FlagArtificial, Elements,
RuntimeLang, VTableHolder, TemplateParams, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr));
EXPECT_EQ(&CT, DICompositeType::buildODRType(
Context, UUID, 0, Name, File, Line, Scope, BaseType,
SizeInBits, AlignInBits, OffsetInBits, NumExtraInhabitants,
DINode::FlagArtificial, Elements, RuntimeLang,
VTableHolder, TemplateParams, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr));

// Confirm that all the right fields got updated.
#define DO_FOR_FIELD(X) EXPECT_EQ(X, CT.getRaw##X());
Expand Down
33 changes: 19 additions & 14 deletions llvm/unittests/IR/MetadataTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1773,44 +1773,49 @@ TEST_F(DIEnumeratorTest, getWithLargeValues) {
typedef MetadataTest DIBasicTypeTest;

TEST_F(DIBasicTypeTest, get) {
auto *N =
DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33, 26, 7,
DINode::FlagZero);
auto *N = DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33,
26, 7, 100, DINode::FlagZero);
EXPECT_EQ(dwarf::DW_TAG_base_type, N->getTag());
EXPECT_EQ("special", N->getName());
EXPECT_EQ(33u, N->getSizeInBits());
EXPECT_EQ(26u, N->getAlignInBits());
EXPECT_EQ(7u, N->getEncoding());
EXPECT_EQ(0u, N->getLine());
EXPECT_EQ(100u, N->getNumExtraInhabitants());
EXPECT_EQ(DINode::FlagZero, N->getFlags());
EXPECT_EQ(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33,
26, 7, DINode::FlagZero));
26, 7, 100, DINode::FlagZero));

EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_unspecified_type,
"special", 33, 26, 7, DINode::FlagZero));
"special", 33, 26, 7,100, DINode::FlagZero));
EXPECT_NE(N,
DIBasicType::get(Context, dwarf::DW_TAG_base_type, "s", 33, 26, 7,
DIBasicType::get(Context, dwarf::DW_TAG_base_type, "s", 33, 26, 7, 100,
DINode::FlagZero));
EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 32,
26, 7, DINode::FlagZero));
26, 7, 100, DINode::FlagZero));
EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33,
25, 7, 100, DINode::FlagZero));

EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33,
25, 7, DINode::FlagZero));
26, 7, 99, DINode::FlagZero));
EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33,
26, 6, DINode::FlagZero));
26, 6, 100, DINode::FlagZero));
EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33,
26, 7, DINode::FlagBigEndian));
26, 7, 100, DINode::FlagBigEndian));
EXPECT_NE(N, DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", 33,
26, 7, DINode::FlagLittleEndian));
26, 7, 100, DINode::FlagLittleEndian));

TempDIBasicType Temp = N->clone();
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
}

TEST_F(DIBasicTypeTest, getWithLargeValues) {
auto *N = DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special",
UINT64_MAX, UINT32_MAX - 1, 7, DINode::FlagZero);
auto *N =
DIBasicType::get(Context, dwarf::DW_TAG_base_type, "special", UINT64_MAX,
UINT32_MAX - 1, 7, UINT32_MAX, DINode::FlagZero);
EXPECT_EQ(UINT64_MAX, N->getSizeInBits());
EXPECT_EQ(UINT32_MAX - 1, N->getAlignInBits());
EXPECT_EQ(UINT32_MAX, N->getNumExtraInhabitants());
}

TEST_F(DIBasicTypeTest, getUnspecified) {
Expand All @@ -1830,7 +1835,7 @@ typedef MetadataTest DITypeTest;
TEST_F(DITypeTest, clone) {
// Check that DIType has a specialized clone that returns TempDIType.
DIType *N = DIBasicType::get(Context, dwarf::DW_TAG_base_type, "int", 32, 32,
dwarf::DW_ATE_signed, DINode::FlagZero);
0, dwarf::DW_ATE_signed, DINode::FlagZero);

TempDIType Temp = N->clone();
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
Expand Down