#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
+#include "llvm/IR/ModuleSlotTracker.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/raw_ostream.h"
EXPECT_PRINTER_EQ("!0 = distinct !{}", N0->print(OS, &M));
EXPECT_PRINTER_EQ("!1 = distinct !{}", N1->print(OS, &M));
+
+ ModuleSlotTracker MST(&M);
+ EXPECT_PRINTER_EQ("!0 = distinct !{}", N0->print(OS, MST));
+ EXPECT_PRINTER_EQ("!1 = distinct !{}", N1->print(OS, MST));
}
TEST_F(MDNodeTest, PrintFromMetadataAsValue) {
EXPECT_PRINTER_EQ("!1", MAV1->printAsOperand(OS, false));
EXPECT_PRINTER_EQ("metadata !0", MAV0->printAsOperand(OS, true));
EXPECT_PRINTER_EQ("metadata !1", MAV1->printAsOperand(OS, true));
+
+ ModuleSlotTracker MST(&M);
+ EXPECT_PRINTER_EQ("!0 = distinct !{}", MAV0->print(OS, MST));
+ EXPECT_PRINTER_EQ("!1 = distinct !{}", MAV1->print(OS, MST));
+ EXPECT_PRINTER_EQ("!0", MAV0->printAsOperand(OS, false, MST));
+ EXPECT_PRINTER_EQ("!1", MAV1->printAsOperand(OS, false, MST));
+ EXPECT_PRINTER_EQ("metadata !0", MAV0->printAsOperand(OS, true, MST));
+ EXPECT_PRINTER_EQ("metadata !1", MAV1->printAsOperand(OS, true, MST));
}
#undef EXPECT_PRINTER_EQ
EXPECT_TRUE(T->isTemporary());
}
+#if defined(GTEST_HAS_DEATH_TEST) && !defined(NDEBUG)
+
+TEST_F(MDNodeTest, deathOnNoReplaceTemporaryRAUW) {
+ auto Temp = MDNode::getTemporary(Context, None);
+ Temp->setCanReplace(false);
+ EXPECT_DEATH(Temp->replaceAllUsesWith(nullptr),
+ "Attempted to replace Metadata marked for no replacement");
+ Temp->setCanReplace(true);
+ // Remove the references to Temp; required for teardown.
+ Temp->replaceAllUsesWith(nullptr);
+}
+
+#endif
+
TEST_F(MDNodeTest, getDistinctWithUnresolvedOperands) {
// temporary !{}
auto Temp = MDTuple::getTemporary(Context, None);
EXPECT_FALSE(L->isResolved());
}
+TEST_F(DILocationTest, cloneTemporary) {
+ MDNode *N = MDNode::get(Context, None);
+ auto L = DILocation::getTemporary(Context, 2, 7, N);
+ EXPECT_TRUE(L->isTemporary());
+ auto L2 = L->clone();
+ EXPECT_TRUE(L2->isTemporary());
+}
+
typedef MetadataTest GenericDINodeTest;
TEST_F(GenericDINodeTest, get) {
EXPECT_EQ(nullptr, N->getScope());
EXPECT_EQ(nullptr, N->getFile());
EXPECT_EQ("", N->getName());
- EXPECT_EQ(nullptr, N->getBaseType());
- EXPECT_EQ(nullptr, N->getVTableHolder());
- EXPECT_EQ(nullptr, N->getTemplateParams().get());
- EXPECT_EQ("", N->getIdentifier());
}
typedef MetadataTest DIFileTest;
MDTuple *Subprograms = getTuple();
MDTuple *GlobalVariables = getTuple();
MDTuple *ImportedEntities = getTuple();
- auto *N = DICompileUnit::get(
+ uint64_t DWOId = 0x10000000c0ffee;
+ MDTuple *Macros = getTuple();
+ auto *N = DICompileUnit::getDistinct(
Context, SourceLanguage, File, Producer, IsOptimized, Flags,
RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
- RetainedTypes, Subprograms, GlobalVariables, ImportedEntities);
+ RetainedTypes, Subprograms, GlobalVariables, ImportedEntities, Macros,
+ DWOId);
EXPECT_EQ(dwarf::DW_TAG_compile_unit, N->getTag());
EXPECT_EQ(SourceLanguage, N->getSourceLanguage());
EXPECT_EQ(Subprograms, N->getSubprograms().get());
EXPECT_EQ(GlobalVariables, N->getGlobalVariables().get());
EXPECT_EQ(ImportedEntities, N->getImportedEntities().get());
- EXPECT_EQ(N, DICompileUnit::get(Context, SourceLanguage, File, Producer,
- IsOptimized, Flags, RuntimeVersion,
- SplitDebugFilename, EmissionKind, EnumTypes,
- RetainedTypes, Subprograms, GlobalVariables,
- ImportedEntities));
-
- EXPECT_NE(N, DICompileUnit::get(Context, SourceLanguage + 1, File, Producer,
- IsOptimized, Flags, RuntimeVersion,
- SplitDebugFilename, EmissionKind, EnumTypes,
- RetainedTypes, Subprograms, GlobalVariables,
- ImportedEntities));
- EXPECT_NE(N, DICompileUnit::get(Context, SourceLanguage, getFile(), Producer,
- IsOptimized, Flags, RuntimeVersion,
- SplitDebugFilename, EmissionKind, EnumTypes,
- RetainedTypes, Subprograms, GlobalVariables,
- ImportedEntities));
- EXPECT_NE(N, DICompileUnit::get(Context, SourceLanguage, File, "other",
- IsOptimized, Flags, RuntimeVersion,
- SplitDebugFilename, EmissionKind, EnumTypes,
- RetainedTypes, Subprograms, GlobalVariables,
- ImportedEntities));
- EXPECT_NE(N, DICompileUnit::get(Context, SourceLanguage, File, Producer,
- !IsOptimized, Flags, RuntimeVersion,
- SplitDebugFilename, EmissionKind, EnumTypes,
- RetainedTypes, Subprograms, GlobalVariables,
- ImportedEntities));
- EXPECT_NE(N, DICompileUnit::get(Context, SourceLanguage, File, Producer,
- IsOptimized, "other", RuntimeVersion,
- SplitDebugFilename, EmissionKind, EnumTypes,
- RetainedTypes, Subprograms, GlobalVariables,
- ImportedEntities));
- EXPECT_NE(N, DICompileUnit::get(Context, SourceLanguage, File, Producer,
- IsOptimized, Flags, RuntimeVersion + 1,
- SplitDebugFilename, EmissionKind, EnumTypes,
- RetainedTypes, Subprograms, GlobalVariables,
- ImportedEntities));
- EXPECT_NE(N,
- DICompileUnit::get(Context, SourceLanguage, File, Producer,
- IsOptimized, Flags, RuntimeVersion, "other",
- EmissionKind, EnumTypes, RetainedTypes,
- Subprograms, GlobalVariables, ImportedEntities));
- EXPECT_NE(N, DICompileUnit::get(Context, SourceLanguage, File, Producer,
- IsOptimized, Flags, RuntimeVersion,
- SplitDebugFilename, EmissionKind + 1,
- EnumTypes, RetainedTypes, Subprograms,
- GlobalVariables, ImportedEntities));
- EXPECT_NE(N, DICompileUnit::get(Context, SourceLanguage, File, Producer,
- IsOptimized, Flags, RuntimeVersion,
- SplitDebugFilename, EmissionKind, getTuple(),
- RetainedTypes, Subprograms, GlobalVariables,
- ImportedEntities));
- EXPECT_NE(N, DICompileUnit::get(
- Context, SourceLanguage, File, Producer, IsOptimized, Flags,
- RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
- getTuple(), Subprograms, GlobalVariables, ImportedEntities));
- EXPECT_NE(N, DICompileUnit::get(Context, SourceLanguage, File, Producer,
- IsOptimized, Flags, RuntimeVersion,
- SplitDebugFilename, EmissionKind, EnumTypes,
- RetainedTypes, getTuple(), GlobalVariables,
- ImportedEntities));
- EXPECT_NE(N, DICompileUnit::get(
- Context, SourceLanguage, File, Producer, IsOptimized, Flags,
- RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
- RetainedTypes, Subprograms, getTuple(), ImportedEntities));
- EXPECT_NE(N, DICompileUnit::get(
- Context, SourceLanguage, File, Producer, IsOptimized, Flags,
- RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
- RetainedTypes, Subprograms, GlobalVariables, getTuple()));
+ EXPECT_EQ(Macros, N->getMacros().get());
+ EXPECT_EQ(DWOId, N->getDWOId());
TempDICompileUnit Temp = N->clone();
- EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
+ EXPECT_EQ(dwarf::DW_TAG_compile_unit, Temp->getTag());
+ EXPECT_EQ(SourceLanguage, Temp->getSourceLanguage());
+ EXPECT_EQ(File, Temp->getFile());
+ EXPECT_EQ(Producer, Temp->getProducer());
+ EXPECT_EQ(IsOptimized, Temp->isOptimized());
+ EXPECT_EQ(Flags, Temp->getFlags());
+ EXPECT_EQ(RuntimeVersion, Temp->getRuntimeVersion());
+ EXPECT_EQ(SplitDebugFilename, Temp->getSplitDebugFilename());
+ EXPECT_EQ(EmissionKind, Temp->getEmissionKind());
+ EXPECT_EQ(EnumTypes, Temp->getEnumTypes().get());
+ EXPECT_EQ(RetainedTypes, Temp->getRetainedTypes().get());
+ EXPECT_EQ(Subprograms, Temp->getSubprograms().get());
+ EXPECT_EQ(GlobalVariables, Temp->getGlobalVariables().get());
+ EXPECT_EQ(ImportedEntities, Temp->getImportedEntities().get());
+ EXPECT_EQ(Macros, Temp->getMacros().get());
+ EXPECT_EQ(DWOId, Temp->getDWOId());
+
+ auto *TempAddress = Temp.get();
+ auto *Clone = MDNode::replaceWithPermanent(std::move(Temp));
+ EXPECT_TRUE(Clone->isDistinct());
+ EXPECT_EQ(TempAddress, Clone);
}
TEST_F(DICompileUnitTest, replaceArrays) {
MDTuple *EnumTypes = MDTuple::getDistinct(Context, None);
MDTuple *RetainedTypes = MDTuple::getDistinct(Context, None);
MDTuple *ImportedEntities = MDTuple::getDistinct(Context, None);
- auto *N = DICompileUnit::get(
+ uint64_t DWOId = 0xc0ffee;
+ auto *N = DICompileUnit::getDistinct(
Context, SourceLanguage, File, Producer, IsOptimized, Flags,
RuntimeVersion, SplitDebugFilename, EmissionKind, EnumTypes,
- RetainedTypes, nullptr, nullptr, ImportedEntities);
+ RetainedTypes, nullptr, nullptr, ImportedEntities, nullptr, DWOId);
auto *Subprograms = MDTuple::getDistinct(Context, None);
EXPECT_EQ(nullptr, N->getSubprograms().get());
EXPECT_EQ(GlobalVariables, N->getGlobalVariables().get());
N->replaceGlobalVariables(nullptr);
EXPECT_EQ(nullptr, N->getGlobalVariables().get());
+
+ auto *Macros = MDTuple::getDistinct(Context, None);
+ EXPECT_EQ(nullptr, N->getMacros().get());
+ N->replaceMacros(Macros);
+ EXPECT_EQ(Macros, N->getMacros().get());
+ N->replaceMacros(nullptr);
+ EXPECT_EQ(nullptr, N->getMacros().get());
}
typedef MetadataTest DISubprogramTest;
unsigned VirtualIndex = 5;
unsigned Flags = 6;
bool IsOptimized = false;
- llvm::Function *Function = getFunction("foo");
MDTuple *TemplateParams = getTuple();
DISubprogram *Declaration = getSubprogram();
MDTuple *Variables = getTuple();
auto *N = DISubprogram::get(
Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags,
- IsOptimized, Function, TemplateParams, Declaration, Variables);
+ IsOptimized, TemplateParams, Declaration, Variables);
EXPECT_EQ(dwarf::DW_TAG_subprogram, N->getTag());
EXPECT_EQ(Scope, N->getScope());
EXPECT_EQ(VirtualIndex, N->getVirtualIndex());
EXPECT_EQ(Flags, N->getFlags());
EXPECT_EQ(IsOptimized, N->isOptimized());
- EXPECT_EQ(Function, N->getFunction());
EXPECT_EQ(TemplateParams, N->getTemplateParams().get());
EXPECT_EQ(Declaration, N->getDeclaration());
EXPECT_EQ(Variables, N->getVariables().get());
EXPECT_EQ(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line,
Type, IsLocalToUnit, IsDefinition, ScopeLine,
ContainingType, Virtuality, VirtualIndex,
- Flags, IsOptimized, Function, TemplateParams,
+ Flags, IsOptimized, TemplateParams,
Declaration, Variables));
EXPECT_NE(N, DISubprogram::get(Context, getCompositeType(), Name, LinkageName,
File, Line, Type, IsLocalToUnit, IsDefinition,
ScopeLine, ContainingType, Virtuality,
- VirtualIndex, Flags, IsOptimized, Function,
+ VirtualIndex, Flags, IsOptimized,
TemplateParams, Declaration, Variables));
EXPECT_NE(N, DISubprogram::get(Context, Scope, "other", LinkageName, File,
Line, Type, IsLocalToUnit, IsDefinition,
ScopeLine, ContainingType, Virtuality,
- VirtualIndex, Flags, IsOptimized, Function,
+ VirtualIndex, Flags, IsOptimized,
TemplateParams, Declaration, Variables));
EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, "other", File, Line,
Type, IsLocalToUnit, IsDefinition, ScopeLine,
ContainingType, Virtuality, VirtualIndex,
- Flags, IsOptimized, Function, TemplateParams,
+ Flags, IsOptimized, TemplateParams,
Declaration, Variables));
EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, getFile(),
Line, Type, IsLocalToUnit, IsDefinition,
ScopeLine, ContainingType, Virtuality,
- VirtualIndex, Flags, IsOptimized, Function,
+ VirtualIndex, Flags, IsOptimized,
TemplateParams, Declaration, Variables));
EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File,
Line + 1, Type, IsLocalToUnit, IsDefinition,
ScopeLine, ContainingType, Virtuality,
- VirtualIndex, Flags, IsOptimized, Function,
+ VirtualIndex, Flags, IsOptimized,
+ TemplateParams, Declaration, Variables));
+ EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line,
+ getSubroutineType(), IsLocalToUnit,
+ IsDefinition, ScopeLine, ContainingType,
+ Virtuality, VirtualIndex, Flags, IsOptimized,
TemplateParams, Declaration, Variables));
- EXPECT_NE(N, DISubprogram::get(
- Context, Scope, Name, LinkageName, File, Line,
- getSubroutineType(), IsLocalToUnit, IsDefinition, ScopeLine,
- ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
- Function, TemplateParams, Declaration, Variables));
EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line,
Type, !IsLocalToUnit, IsDefinition, ScopeLine,
ContainingType, Virtuality, VirtualIndex,
- Flags, IsOptimized, Function, TemplateParams,
+ Flags, IsOptimized, TemplateParams,
Declaration, Variables));
EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line,
Type, IsLocalToUnit, !IsDefinition, ScopeLine,
ContainingType, Virtuality, VirtualIndex,
- Flags, IsOptimized, Function, TemplateParams,
+ Flags, IsOptimized, TemplateParams,
Declaration, Variables));
EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line,
Type, IsLocalToUnit, IsDefinition,
ScopeLine + 1, ContainingType, Virtuality,
- VirtualIndex, Flags, IsOptimized, Function,
+ VirtualIndex, Flags, IsOptimized,
TemplateParams, Declaration, Variables));
EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line,
Type, IsLocalToUnit, IsDefinition, ScopeLine,
getCompositeType(), Virtuality, VirtualIndex,
- Flags, IsOptimized, Function, TemplateParams,
+ Flags, IsOptimized, TemplateParams,
Declaration, Variables));
EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line,
Type, IsLocalToUnit, IsDefinition, ScopeLine,
ContainingType, Virtuality + 1, VirtualIndex,
- Flags, IsOptimized, Function, TemplateParams,
+ Flags, IsOptimized, TemplateParams,
Declaration, Variables));
EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line,
Type, IsLocalToUnit, IsDefinition, ScopeLine,
ContainingType, Virtuality, VirtualIndex + 1,
- Flags, IsOptimized, Function, TemplateParams,
+ Flags, IsOptimized, TemplateParams,
Declaration, Variables));
EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line,
Type, IsLocalToUnit, IsDefinition, ScopeLine,
ContainingType, Virtuality, VirtualIndex,
- ~Flags, IsOptimized, Function, TemplateParams,
+ ~Flags, IsOptimized, TemplateParams,
Declaration, Variables));
EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line,
Type, IsLocalToUnit, IsDefinition, ScopeLine,
ContainingType, Virtuality, VirtualIndex,
- Flags, !IsOptimized, Function, TemplateParams,
- Declaration, Variables));
- EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line,
- Type, IsLocalToUnit, IsDefinition, ScopeLine,
- ContainingType, Virtuality, VirtualIndex,
- Flags, IsOptimized, getFunction("bar"),
- TemplateParams, Declaration, Variables));
- EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line,
- Type, IsLocalToUnit, IsDefinition, ScopeLine,
- ContainingType, Virtuality, VirtualIndex,
- Flags, IsOptimized, Function, getTuple(),
+ Flags, !IsOptimized, TemplateParams,
Declaration, Variables));
+ EXPECT_NE(N,
+ DISubprogram::get(Context, Scope, Name, LinkageName, File, Line,
+ Type, IsLocalToUnit, IsDefinition, ScopeLine,
+ ContainingType, Virtuality, VirtualIndex, Flags,
+ IsOptimized, getTuple(), Declaration, Variables));
EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line,
Type, IsLocalToUnit, IsDefinition, ScopeLine,
ContainingType, Virtuality, VirtualIndex,
- Flags, IsOptimized, Function, TemplateParams,
+ Flags, IsOptimized, TemplateParams,
getSubprogram(), Variables));
EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line,
Type, IsLocalToUnit, IsDefinition, ScopeLine,
ContainingType, Virtuality, VirtualIndex,
- Flags, IsOptimized, Function, TemplateParams,
+ Flags, IsOptimized, TemplateParams,
Declaration, getTuple()));
TempDISubprogram Temp = N->clone();
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
}
-TEST_F(DISubprogramTest, replaceFunction) {
- DIScopeRef Scope = getCompositeType();
- StringRef Name = "name";
- StringRef LinkageName = "linkage";
- DIFile *File = getFile();
- unsigned Line = 2;
- DISubroutineType *Type = getSubroutineType();
- bool IsLocalToUnit = false;
- bool IsDefinition = true;
- unsigned ScopeLine = 3;
- DITypeRef ContainingType = getCompositeType();
- unsigned Virtuality = 4;
- unsigned VirtualIndex = 5;
- unsigned Flags = 6;
- bool IsOptimized = false;
- MDTuple *TemplateParams = getTuple();
- DISubprogram *Declaration = getSubprogram();
- MDTuple *Variables = getTuple();
-
- auto *N = DISubprogram::get(
- Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
- IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags,
- IsOptimized, nullptr, TemplateParams, Declaration, Variables);
-
- EXPECT_EQ(nullptr, N->getFunction());
-
- std::unique_ptr<Function> F(
- Function::Create(FunctionType::get(Type::getVoidTy(Context), false),
- GlobalValue::ExternalLinkage));
- N->replaceFunction(F.get());
- EXPECT_EQ(F.get(), N->getFunction());
-
- N->replaceFunction(nullptr);
- EXPECT_EQ(nullptr, N->getFunction());
-}
-
typedef MetadataTest DILexicalBlockTest;
TEST_F(DILexicalBlockTest, get) {
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
}
+TEST_F(DILexicalBlockTest, Overflow) {
+ DISubprogram *SP = getSubprogram();
+ DIFile *F = getFile();
+ {
+ auto *LB = DILexicalBlock::get(Context, SP, F, 2, 7);
+ EXPECT_EQ(2u, LB->getLine());
+ EXPECT_EQ(7u, LB->getColumn());
+ }
+ unsigned U16 = 1u << 16;
+ {
+ auto *LB = DILexicalBlock::get(Context, SP, F, UINT32_MAX, U16 - 1);
+ EXPECT_EQ(UINT32_MAX, LB->getLine());
+ EXPECT_EQ(U16 - 1, LB->getColumn());
+ }
+ {
+ auto *LB = DILexicalBlock::get(Context, SP, F, UINT32_MAX, U16);
+ EXPECT_EQ(UINT32_MAX, LB->getLine());
+ EXPECT_EQ(0u, LB->getColumn());
+ }
+ {
+ auto *LB = DILexicalBlock::get(Context, SP, F, UINT32_MAX, U16 + 1);
+ EXPECT_EQ(UINT32_MAX, LB->getLine());
+ EXPECT_EQ(0u, LB->getColumn());
+ }
+}
+
typedef MetadataTest DILexicalBlockFileTest;
TEST_F(DILexicalBlockFileTest, get) {
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
}
+typedef MetadataTest DIModuleTest;
+
+TEST_F(DIModuleTest, get) {
+ DIScope *Scope = getFile();
+ StringRef Name = "module";
+ StringRef ConfigMacro = "-DNDEBUG";
+ StringRef Includes = "-I.";
+ StringRef Sysroot = "/";
+
+ auto *N = DIModule::get(Context, Scope, Name, ConfigMacro, Includes, Sysroot);
+
+ EXPECT_EQ(dwarf::DW_TAG_module, N->getTag());
+ EXPECT_EQ(Scope, N->getScope());
+ EXPECT_EQ(Name, N->getName());
+ EXPECT_EQ(ConfigMacro, N->getConfigurationMacros());
+ EXPECT_EQ(Includes, N->getIncludePath());
+ EXPECT_EQ(Sysroot, N->getISysRoot());
+ EXPECT_EQ(N, DIModule::get(Context, Scope, Name,
+ ConfigMacro, Includes, Sysroot));
+ EXPECT_NE(N, DIModule::get(Context, getFile(), Name,
+ ConfigMacro, Includes, Sysroot));
+ EXPECT_NE(N, DIModule::get(Context, Scope, "other",
+ ConfigMacro, Includes, Sysroot));
+ EXPECT_NE(N, DIModule::get(Context, Scope, Name,
+ "other", Includes, Sysroot));
+ EXPECT_NE(N, DIModule::get(Context, Scope, Name,
+ ConfigMacro, "other", Sysroot));
+ EXPECT_NE(N, DIModule::get(Context, Scope, Name,
+ ConfigMacro, Includes, "other"));
+
+ TempDIModule Temp = N->clone();
+ EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
+}
+
typedef MetadataTest DITemplateTypeParameterTest;
TEST_F(DITemplateTypeParameterTest, get) {
typedef MetadataTest DILocalVariableTest;
TEST_F(DILocalVariableTest, get) {
- unsigned Tag = dwarf::DW_TAG_arg_variable;
DILocalScope *Scope = getSubprogram();
StringRef Name = "name";
DIFile *File = getFile();
unsigned Arg = 6;
unsigned Flags = 7;
- auto *N = DILocalVariable::get(Context, Tag, Scope, Name, File, Line, Type,
- Arg, Flags);
- EXPECT_EQ(Tag, N->getTag());
+ auto *N =
+ DILocalVariable::get(Context, Scope, Name, File, Line, Type, Arg, Flags);
+ EXPECT_TRUE(N->isParameter());
EXPECT_EQ(Scope, N->getScope());
EXPECT_EQ(Name, N->getName());
EXPECT_EQ(File, N->getFile());
EXPECT_EQ(Type, N->getType());
EXPECT_EQ(Arg, N->getArg());
EXPECT_EQ(Flags, N->getFlags());
- EXPECT_EQ(N, DILocalVariable::get(Context, Tag, Scope, Name, File, Line, Type,
- Arg, Flags));
+ EXPECT_EQ(N, DILocalVariable::get(Context, Scope, Name, File, Line, Type, Arg,
+ Flags));
- EXPECT_NE(N, DILocalVariable::get(Context, dwarf::DW_TAG_auto_variable, Scope,
- Name, File, Line, Type, Arg, Flags));
- EXPECT_NE(N, DILocalVariable::get(Context, Tag, getSubprogram(), Name, File,
- Line, Type, Arg, Flags));
- EXPECT_NE(N, DILocalVariable::get(Context, Tag, Scope, "other", File, Line,
+ EXPECT_FALSE(
+ DILocalVariable::get(Context, Scope, Name, File, Line, Type, 0, Flags)
+ ->isParameter());
+ EXPECT_NE(N, DILocalVariable::get(Context, getSubprogram(), Name, File, Line,
Type, Arg, Flags));
- EXPECT_NE(N, DILocalVariable::get(Context, Tag, Scope, Name, getFile(), Line,
- Type, Arg, Flags));
- EXPECT_NE(N, DILocalVariable::get(Context, Tag, Scope, Name, File, Line + 1,
- Type, Arg, Flags));
- EXPECT_NE(N, DILocalVariable::get(Context, Tag, Scope, Name, File, Line,
+ EXPECT_NE(N, DILocalVariable::get(Context, Scope, "other", File, Line, Type,
+ Arg, Flags));
+ EXPECT_NE(N, DILocalVariable::get(Context, Scope, Name, getFile(), Line, Type,
+ Arg, Flags));
+ EXPECT_NE(N, DILocalVariable::get(Context, Scope, Name, File, Line + 1, Type,
+ Arg, Flags));
+ EXPECT_NE(N, DILocalVariable::get(Context, Scope, Name, File, Line,
getDerivedType(), Arg, Flags));
- EXPECT_NE(N, DILocalVariable::get(Context, Tag, Scope, Name, File, Line, Type,
+ EXPECT_NE(N, DILocalVariable::get(Context, Scope, Name, File, Line, Type,
Arg + 1, Flags));
- EXPECT_NE(N, DILocalVariable::get(Context, Tag, Scope, Name, File, Line, Type,
- Arg, ~Flags));
+ EXPECT_NE(N, DILocalVariable::get(Context, Scope, Name, File, Line, Type, Arg,
+ ~Flags));
TempDILocalVariable Temp = N->clone();
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
}
TEST_F(DILocalVariableTest, getArg256) {
- EXPECT_EQ(255u, DILocalVariable::get(Context, dwarf::DW_TAG_arg_variable,
- getSubprogram(), "", getFile(), 0,
- nullptr, 255, 0)
+ EXPECT_EQ(255u, DILocalVariable::get(Context, getSubprogram(), "", getFile(),
+ 0, nullptr, 255, 0)
->getArg());
- EXPECT_EQ(256u, DILocalVariable::get(Context, dwarf::DW_TAG_arg_variable,
- getSubprogram(), "", getFile(), 0,
- nullptr, 256, 0)
+ EXPECT_EQ(256u, DILocalVariable::get(Context, getSubprogram(), "", getFile(),
+ 0, nullptr, 256, 0)
->getArg());
- EXPECT_EQ(257u, DILocalVariable::get(Context, dwarf::DW_TAG_arg_variable,
- getSubprogram(), "", getFile(), 0,
- nullptr, 257, 0)
+ EXPECT_EQ(257u, DILocalVariable::get(Context, getSubprogram(), "", getFile(),
+ 0, nullptr, 257, 0)
->getArg());
unsigned Max = UINT16_MAX;
- EXPECT_EQ(Max, DILocalVariable::get(Context, dwarf::DW_TAG_arg_variable,
- getSubprogram(), "", getFile(), 0,
- nullptr, Max, 0)
+ EXPECT_EQ(Max, DILocalVariable::get(Context, getSubprogram(), "", getFile(),
+ 0, nullptr, Max, 0)
->getArg());
}
StringRef GetterName = "getter";
StringRef SetterName = "setter";
unsigned Attributes = 7;
- DIType *Type = cast<DIBasicType>(getBasicType("basic"));
+ DITypeRef Type = getBasicType("basic");
auto *N = DIObjCProperty::get(Context, Name, File, Line, GetterName,
SetterName, Attributes, Type);
SetterName, Attributes + 1, Type));
EXPECT_NE(N, DIObjCProperty::get(Context, Name, File, Line, GetterName,
SetterName, Attributes,
- cast<DIBasicType>(getBasicType("other"))));
+ getBasicType("other")));
TempDIObjCProperty Temp = N->clone();
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
EXPECT_EQ(12304u, *F->getEntryCount());
}
+TEST_F(FunctionAttachmentTest, SubprogramAttachment) {
+ Function *F = getFunction("foo");
+ DISubprogram *SP = getSubprogram();
+ F->setSubprogram(SP);
+
+ // Note that the static_cast confirms that F->getSubprogram() actually
+ // returns an DISubprogram.
+ EXPECT_EQ(SP, static_cast<DISubprogram *>(F->getSubprogram()));
+ EXPECT_EQ(SP, F->getMetadata("dbg"));
+ EXPECT_EQ(SP, F->getMetadata(LLVMContext::MD_dbg));
+}
+
}