diff options
Diffstat (limited to 'unittests/IR/MetadataTest.cpp')
-rw-r--r-- | unittests/IR/MetadataTest.cpp | 187 |
1 files changed, 140 insertions, 47 deletions
diff --git a/unittests/IR/MetadataTest.cpp b/unittests/IR/MetadataTest.cpp index 672de55fbdea..84a7b02fa983 100644 --- a/unittests/IR/MetadataTest.cpp +++ b/unittests/IR/MetadataTest.cpp @@ -932,8 +932,11 @@ typedef MetadataTest DISubrangeTest; TEST_F(DISubrangeTest, get) { auto *N = DISubrange::get(Context, 5, 7); + auto Count = N->getCount(); EXPECT_EQ(dwarf::DW_TAG_subrange_type, N->getTag()); - EXPECT_EQ(5, N->getCount()); + ASSERT_TRUE(Count); + ASSERT_TRUE(Count.is<ConstantInt*>()); + EXPECT_EQ(5, Count.get<ConstantInt*>()->getSExtValue()); EXPECT_EQ(7, N->getLowerBound()); EXPECT_EQ(N, DISubrange::get(Context, 5, 7)); EXPECT_EQ(DISubrange::get(Context, 5, 0), DISubrange::get(Context, 5)); @@ -944,23 +947,47 @@ TEST_F(DISubrangeTest, get) { TEST_F(DISubrangeTest, getEmptyArray) { auto *N = DISubrange::get(Context, -1, 0); + auto Count = N->getCount(); EXPECT_EQ(dwarf::DW_TAG_subrange_type, N->getTag()); - EXPECT_EQ(-1, N->getCount()); + ASSERT_TRUE(Count); + ASSERT_TRUE(Count.is<ConstantInt*>()); + EXPECT_EQ(-1, Count.get<ConstantInt*>()->getSExtValue()); EXPECT_EQ(0, N->getLowerBound()); EXPECT_EQ(N, DISubrange::get(Context, -1, 0)); } +TEST_F(DISubrangeTest, getVariableCount) { + DILocalScope *Scope = getSubprogram(); + DIFile *File = getFile(); + DIType *Type = getDerivedType(); + DINode::DIFlags Flags = static_cast<DINode::DIFlags>(7); + auto *VlaExpr = DILocalVariable::get(Context, Scope, "vla_expr", File, 8, + Type, 2, Flags, 8); + + auto *N = DISubrange::get(Context, VlaExpr, 0); + auto Count = N->getCount(); + ASSERT_TRUE(Count); + ASSERT_TRUE(Count.is<DIVariable*>()); + EXPECT_EQ(VlaExpr, Count.get<DIVariable*>()); + ASSERT_TRUE(isa<DIVariable>(N->getRawCountNode())); + EXPECT_EQ(0, N->getLowerBound()); + EXPECT_EQ("vla_expr", Count.get<DIVariable*>()->getName()); + EXPECT_EQ(N, DISubrange::get(Context, VlaExpr, 0)); +} + typedef MetadataTest DIEnumeratorTest; TEST_F(DIEnumeratorTest, get) { - auto *N = DIEnumerator::get(Context, 7, "name"); + auto *N = DIEnumerator::get(Context, 7, false, "name"); EXPECT_EQ(dwarf::DW_TAG_enumerator, N->getTag()); EXPECT_EQ(7, N->getValue()); + EXPECT_FALSE(N->isUnsigned()); EXPECT_EQ("name", N->getName()); - EXPECT_EQ(N, DIEnumerator::get(Context, 7, "name")); + EXPECT_EQ(N, DIEnumerator::get(Context, 7, false, "name")); - EXPECT_NE(N, DIEnumerator::get(Context, 8, "name")); - EXPECT_NE(N, DIEnumerator::get(Context, 7, "nam")); + EXPECT_NE(N, DIEnumerator::get(Context, 7, true, "name")); + EXPECT_NE(N, DIEnumerator::get(Context, 8, false, "name")); + EXPECT_NE(N, DIEnumerator::get(Context, 7, false, "nam")); TempDIEnumerator Temp = N->clone(); EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); @@ -1024,7 +1051,7 @@ TEST_F(DITypeTest, clone) { EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); } -TEST_F(DITypeTest, setFlags) { +TEST_F(DITypeTest, cloneWithFlags) { // void (void) Metadata *TypesOps[] = {nullptr}; Metadata *Types = MDTuple::get(Context, TypesOps); @@ -1032,17 +1059,15 @@ TEST_F(DITypeTest, setFlags) { DIType *D = DISubroutineType::getDistinct(Context, DINode::FlagZero, 0, Types); EXPECT_EQ(DINode::FlagZero, D->getFlags()); - D->setFlags(DINode::FlagRValueReference); - EXPECT_EQ(DINode::FlagRValueReference, D->getFlags()); - D->setFlags(DINode::FlagZero); + TempDIType D2 = D->cloneWithFlags(DINode::FlagRValueReference); + EXPECT_EQ(DINode::FlagRValueReference, D2->getFlags()); EXPECT_EQ(DINode::FlagZero, D->getFlags()); TempDIType T = DISubroutineType::getTemporary(Context, DINode::FlagZero, 0, Types); EXPECT_EQ(DINode::FlagZero, T->getFlags()); - T->setFlags(DINode::FlagRValueReference); - EXPECT_EQ(DINode::FlagRValueReference, T->getFlags()); - T->setFlags(DINode::FlagZero); + TempDIType T2 = T->cloneWithFlags(DINode::FlagRValueReference); + EXPECT_EQ(DINode::FlagRValueReference, T2->getFlags()); EXPECT_EQ(DINode::FlagZero, T->getFlags()); } @@ -1330,6 +1355,51 @@ TEST_F(DICompositeTypeTest, replaceOperands) { EXPECT_EQ(nullptr, N->getTemplateParams().get()); } +TEST_F(DICompositeTypeTest, variant_part) { + unsigned Tag = dwarf::DW_TAG_variant_part; + StringRef Name = "some name"; + DIFile *File = getFile(); + unsigned Line = 1; + DIScope *Scope = getSubprogram(); + DIType *BaseType = getCompositeType(); + uint64_t SizeInBits = 2; + uint32_t AlignInBits = 3; + uint64_t OffsetInBits = 4; + DINode::DIFlags Flags = static_cast<DINode::DIFlags>(5); + unsigned RuntimeLang = 6; + StringRef Identifier = "some id"; + DIDerivedType *Discriminator = cast<DIDerivedType>(getDerivedType()); + DIDerivedType *Discriminator2 = cast<DIDerivedType>(getDerivedType()); + + EXPECT_NE(Discriminator, Discriminator2); + + auto *N = DICompositeType::get( + Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits, + OffsetInBits, Flags, nullptr, RuntimeLang, nullptr, nullptr, Identifier, + Discriminator); + + // Test the hashing. + auto *Same = DICompositeType::get( + Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits, + OffsetInBits, Flags, nullptr, RuntimeLang, nullptr, nullptr, Identifier, + Discriminator); + auto *Other = DICompositeType::get( + Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits, + OffsetInBits, Flags, nullptr, RuntimeLang, nullptr, nullptr, Identifier, + Discriminator2); + auto *NoDisc = DICompositeType::get( + Context, Tag, Name, File, Line, Scope, BaseType, SizeInBits, AlignInBits, + OffsetInBits, Flags, nullptr, RuntimeLang, nullptr, nullptr, Identifier, + nullptr); + + EXPECT_EQ(N, Same); + EXPECT_NE(Same, Other); + EXPECT_NE(Same, NoDisc); + EXPECT_NE(Other, NoDisc); + + EXPECT_EQ(N->getDiscriminator(), Discriminator); +} + typedef MetadataTest DISubroutineTypeTest; TEST_F(DISubroutineTypeTest, get) { @@ -1375,21 +1445,27 @@ typedef MetadataTest DIFileTest; TEST_F(DIFileTest, get) { StringRef Filename = "file"; StringRef Directory = "dir"; - DIFile::ChecksumKind CSKind = DIFile::CSK_MD5; - StringRef Checksum = "000102030405060708090a0b0c0d0e0f"; - auto *N = DIFile::get(Context, Filename, Directory, CSKind, Checksum); + DIFile::ChecksumKind CSKind = DIFile::ChecksumKind::CSK_MD5; + StringRef ChecksumString = "000102030405060708090a0b0c0d0e0f"; + DIFile::ChecksumInfo<StringRef> Checksum(CSKind, ChecksumString); + StringRef Source = "source"; + auto *N = DIFile::get(Context, Filename, Directory, Checksum, Source); EXPECT_EQ(dwarf::DW_TAG_file_type, N->getTag()); EXPECT_EQ(Filename, N->getFilename()); EXPECT_EQ(Directory, N->getDirectory()); - EXPECT_EQ(CSKind, N->getChecksumKind()); EXPECT_EQ(Checksum, N->getChecksum()); - EXPECT_EQ(N, DIFile::get(Context, Filename, Directory, CSKind, Checksum)); + EXPECT_EQ(Source, N->getSource()); + EXPECT_EQ(N, DIFile::get(Context, Filename, Directory, Checksum, Source)); - EXPECT_NE(N, DIFile::get(Context, "other", Directory, CSKind, Checksum)); - EXPECT_NE(N, DIFile::get(Context, Filename, "other", CSKind, Checksum)); + EXPECT_NE(N, DIFile::get(Context, "other", Directory, Checksum, Source)); + EXPECT_NE(N, DIFile::get(Context, Filename, "other", Checksum, Source)); + DIFile::ChecksumInfo<StringRef> OtherChecksum(DIFile::ChecksumKind::CSK_SHA1, ChecksumString); EXPECT_NE( - N, DIFile::get(Context, Filename, Directory, DIFile::CSK_SHA1, Checksum)); + N, DIFile::get(Context, Filename, Directory, OtherChecksum)); + StringRef OtherSource = "other"; + EXPECT_NE(N, DIFile::get(Context, Filename, Directory, Checksum, OtherSource)); + EXPECT_NE(N, DIFile::get(Context, Filename, Directory, Checksum)); EXPECT_NE(N, DIFile::get(Context, Filename, Directory)); TempDIFile Temp = N->clone(); @@ -1518,7 +1594,7 @@ TEST_F(DISubprogramTest, get) { bool IsOptimized = false; MDTuple *TemplateParams = getTuple(); DISubprogram *Declaration = getSubprogram(); - MDTuple *Variables = getTuple(); + MDTuple *RetainedNodes = getTuple(); MDTuple *ThrownTypes = getTuple(); DICompileUnit *Unit = getUnit(); @@ -1526,7 +1602,7 @@ TEST_F(DISubprogramTest, get) { Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment, Flags, IsOptimized, Unit, TemplateParams, Declaration, - Variables, ThrownTypes); + RetainedNodes, ThrownTypes); EXPECT_EQ(dwarf::DW_TAG_subprogram, N->getTag()); EXPECT_EQ(Scope, N->getScope()); @@ -1547,99 +1623,99 @@ TEST_F(DISubprogramTest, get) { EXPECT_EQ(Unit, N->getUnit()); EXPECT_EQ(TemplateParams, N->getTemplateParams().get()); EXPECT_EQ(Declaration, N->getDeclaration()); - EXPECT_EQ(Variables, N->getVariables().get()); + EXPECT_EQ(RetainedNodes, N->getRetainedNodes().get()); EXPECT_EQ(ThrownTypes, N->getThrownTypes().get()); EXPECT_EQ(N, DISubprogram::get( Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment, Flags, IsOptimized, - Unit, TemplateParams, Declaration, Variables, ThrownTypes)); + Unit, TemplateParams, Declaration, RetainedNodes, ThrownTypes)); EXPECT_NE(N, DISubprogram::get( Context, getCompositeType(), Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment, Flags, IsOptimized, - Unit, TemplateParams, Declaration, Variables, ThrownTypes)); + Unit, TemplateParams, Declaration, RetainedNodes, ThrownTypes)); EXPECT_NE(N, DISubprogram::get( Context, Scope, "other", LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment, Flags, IsOptimized, - Unit, TemplateParams, Declaration, Variables, ThrownTypes)); + Unit, TemplateParams, Declaration, RetainedNodes, ThrownTypes)); EXPECT_NE(N, DISubprogram::get( Context, Scope, Name, "other", File, Line, Type, IsLocalToUnit, IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment, Flags, IsOptimized, - Unit, TemplateParams, Declaration, Variables, ThrownTypes)); + Unit, TemplateParams, Declaration, RetainedNodes, ThrownTypes)); EXPECT_NE(N, DISubprogram::get( Context, Scope, Name, LinkageName, getFile(), Line, Type, IsLocalToUnit, IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment, Flags, IsOptimized, - Unit, TemplateParams, Declaration, Variables, ThrownTypes)); + Unit, TemplateParams, Declaration, RetainedNodes, ThrownTypes)); EXPECT_NE(N, DISubprogram::get( Context, Scope, Name, LinkageName, File, Line + 1, Type, IsLocalToUnit, IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment, Flags, IsOptimized, - Unit, TemplateParams, Declaration, Variables, ThrownTypes)); + Unit, TemplateParams, Declaration, RetainedNodes, ThrownTypes)); EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line, getSubroutineType(), IsLocalToUnit, IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment, Flags, IsOptimized, Unit, TemplateParams, - Declaration, Variables, ThrownTypes)); + Declaration, RetainedNodes, ThrownTypes)); EXPECT_NE(N, DISubprogram::get( Context, Scope, Name, LinkageName, File, Line, Type, !IsLocalToUnit, IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment, Flags, IsOptimized, - Unit, TemplateParams, Declaration, Variables, ThrownTypes)); + Unit, TemplateParams, Declaration, RetainedNodes, ThrownTypes)); EXPECT_NE(N, DISubprogram::get( Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, !IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment, Flags, IsOptimized, - Unit, TemplateParams, Declaration, Variables, ThrownTypes)); + Unit, TemplateParams, Declaration, RetainedNodes, ThrownTypes)); EXPECT_NE(N, DISubprogram::get( Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, ScopeLine + 1, ContainingType, Virtuality, VirtualIndex, ThisAdjustment, Flags, IsOptimized, - Unit, TemplateParams, Declaration, Variables, ThrownTypes)); + Unit, TemplateParams, Declaration, RetainedNodes, ThrownTypes)); EXPECT_NE(N, DISubprogram::get( Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, ScopeLine, getCompositeType(), Virtuality, VirtualIndex, ThisAdjustment, Flags, IsOptimized, - Unit, TemplateParams, Declaration, Variables, ThrownTypes)); + Unit, TemplateParams, Declaration, RetainedNodes, ThrownTypes)); EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, ScopeLine, ContainingType, Virtuality + 1, VirtualIndex, ThisAdjustment, Flags, IsOptimized, Unit, - TemplateParams, Declaration, Variables, + TemplateParams, Declaration, RetainedNodes, ThrownTypes)); EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex + 1, ThisAdjustment, Flags, IsOptimized, Unit, - TemplateParams, Declaration, Variables, + TemplateParams, Declaration, RetainedNodes, ThrownTypes)); EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment, Flags, !IsOptimized, Unit, - TemplateParams, Declaration, Variables, + TemplateParams, Declaration, RetainedNodes, ThrownTypes)); EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment, Flags, IsOptimized, nullptr, - TemplateParams, Declaration, Variables, + TemplateParams, Declaration, RetainedNodes, ThrownTypes)); EXPECT_NE(N, DISubprogram::get( Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment, Flags, IsOptimized, - Unit, getTuple(), Declaration, Variables, ThrownTypes)); + Unit, getTuple(), Declaration, RetainedNodes, ThrownTypes)); EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment, Flags, IsOptimized, Unit, - TemplateParams, getSubprogram(), Variables, + TemplateParams, getSubprogram(), RetainedNodes, ThrownTypes)); EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, ScopeLine, @@ -1650,7 +1726,7 @@ TEST_F(DISubprogramTest, get) { Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, ThisAdjustment, Flags, IsOptimized, - Unit, TemplateParams, Declaration, Variables, getTuple())); + Unit, TemplateParams, Declaration, RetainedNodes, getTuple())); TempDISubprogram Temp = N->clone(); EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); @@ -2035,14 +2111,20 @@ TEST_F(DIExpressionTest, get) { // Test DIExpression::prepend(). uint64_t Elts0[] = {dwarf::DW_OP_LLVM_fragment, 0, 32}; auto *N0 = DIExpression::get(Context, Elts0); - N0 = DIExpression::prepend(N0, true, 64, true, true); + auto *N0WithPrependedOps = DIExpression::prepend(N0, true, 64, true, true); uint64_t Elts1[] = {dwarf::DW_OP_deref, dwarf::DW_OP_plus_uconst, 64, dwarf::DW_OP_deref, dwarf::DW_OP_stack_value, dwarf::DW_OP_LLVM_fragment, 0, 32}; auto *N1 = DIExpression::get(Context, Elts1); - EXPECT_EQ(N0, N1); + EXPECT_EQ(N0WithPrependedOps, N1); + + // Test DIExpression::append(). + uint64_t Elts2[] = {dwarf::DW_OP_deref, dwarf::DW_OP_plus_uconst, 64, + dwarf::DW_OP_deref, dwarf::DW_OP_stack_value}; + auto *N2 = DIExpression::append(N0, Elts2); + EXPECT_EQ(N0WithPrependedOps, N2); } TEST_F(DIExpressionTest, isValid) { @@ -2436,9 +2518,20 @@ TEST_F(FunctionAttachmentTest, Verifier) { TEST_F(FunctionAttachmentTest, EntryCount) { Function *F = getFunction("foo"); EXPECT_FALSE(F->getEntryCount().hasValue()); - F->setEntryCount(12304); - EXPECT_TRUE(F->getEntryCount().hasValue()); - EXPECT_EQ(12304u, *F->getEntryCount()); + F->setEntryCount(12304, Function::PCT_Real); + auto Count = F->getEntryCount(); + EXPECT_TRUE(Count.hasValue()); + EXPECT_EQ(12304u, Count.getCount()); + EXPECT_EQ(Function::PCT_Real, Count.getType()); + + // Repeat the same for synthetic counts. + F = getFunction("bar"); + EXPECT_FALSE(F->getEntryCount().hasValue()); + F->setEntryCount(123, Function::PCT_Synthetic); + Count = F->getEntryCount(); + EXPECT_TRUE(Count.hasValue()); + EXPECT_EQ(123u, Count.getCount()); + EXPECT_EQ(Function::PCT_Synthetic, Count.getType()); } TEST_F(FunctionAttachmentTest, SubprogramAttachment) { |