diff options
Diffstat (limited to 'llvm/unittests/IR/LLVMContextTest.cpp')
-rw-r--r-- | llvm/unittests/IR/LLVMContextTest.cpp | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/llvm/unittests/IR/LLVMContextTest.cpp b/llvm/unittests/IR/LLVMContextTest.cpp index 028dc68827b..37656a9b83a 100644 --- a/llvm/unittests/IR/LLVMContextTest.cpp +++ b/llvm/unittests/IR/LLVMContextTest.cpp @@ -25,35 +25,41 @@ TEST(LLVMContextTest, enableDebugTypeODRUniquing) { TEST(LLVMContextTest, getOrInsertODRUniquedType) { LLVMContext Context; - const MDString &S = *MDString::get(Context, "string"); + MDString &UUID = *MDString::get(Context, "string"); // Without a type map, this should return null. - EXPECT_FALSE(Context.getOrInsertODRUniquedType(S)); + EXPECT_FALSE(DICompositeType::getODRType( + Context, UUID, dwarf::DW_TAG_class_type, nullptr, nullptr, 0, nullptr, + nullptr, 0, 0, 0, 0, nullptr, 0, nullptr, nullptr)); - // Get the mapping. + // Enable the mapping. There still shouldn't be a type. Context.enableDebugTypeODRUniquing(); - DICompositeType **Mapping = Context.getOrInsertODRUniquedType(S); - ASSERT_TRUE(Mapping); + EXPECT_FALSE(DICompositeType::getODRTypeIfExists(Context, UUID)); - // Create some type and add it to the mapping. - auto &CT = *DICompositeType::get(Context, dwarf::DW_TAG_class_type, "name", - nullptr, 0, nullptr, nullptr, 0, 0, 0, 0, - nullptr, 0, nullptr, nullptr, S.getString()); - ASSERT_EQ(S.getString(), CT.getIdentifier()); - *Mapping = &CT; + // Create some ODR-uniqued type. + auto &CT = *DICompositeType::getODRType( + Context, UUID, dwarf::DW_TAG_class_type, nullptr, nullptr, 0, nullptr, + nullptr, 0, 0, 0, 0, nullptr, 0, nullptr, nullptr); + EXPECT_EQ(UUID.getString(), CT.getIdentifier()); - // Check that we get it back. - Mapping = Context.getOrInsertODRUniquedType(S); - ASSERT_TRUE(Mapping); - EXPECT_EQ(&CT, *Mapping); + // Check that we get it back, even if we change a field. + EXPECT_EQ(&CT, DICompositeType::getODRTypeIfExists(Context, UUID)); + EXPECT_EQ( + &CT, DICompositeType::getODRType(Context, UUID, dwarf::DW_TAG_class_type, + nullptr, nullptr, 0, nullptr, nullptr, 0, + 0, 0, 0, nullptr, 0, 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, 0, nullptr, 0, nullptr, nullptr)); // Check that it's discarded with the type map. Context.disableDebugTypeODRUniquing(); - EXPECT_FALSE(Context.getOrInsertODRUniquedType(S)); + EXPECT_FALSE(DICompositeType::getODRTypeIfExists(Context, UUID)); // And it shouldn't magically reappear... Context.enableDebugTypeODRUniquing(); - EXPECT_FALSE(*Context.getOrInsertODRUniquedType(S)); + EXPECT_FALSE(DICompositeType::getODRTypeIfExists(Context, UUID)); } } // end namespace |