[llvm] r233559 - Verifier: Check operands of MDSubprogram nodes
Duncan P. N. Exon Smith
dexonsmith at apple.com
Mon Mar 30 09:19:15 PDT 2015
Author: dexonsmith
Date: Mon Mar 30 11:19:15 2015
New Revision: 233559
URL: http://llvm.org/viewvc/llvm-project?rev=233559&view=rev
Log:
Verifier: Check operands of MDSubprogram nodes
Check operands of `MDSubprogram`s in the verifier, and update the
accessors and factory functions to use more specific types.
There were a lot of broken testcases, which I fixed in r233466. If you
have out-of-tree tests for debug info, you probably need similar changes
to the ones I made there.
Modified:
llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
llvm/trunk/lib/IR/AsmWriter.cpp
llvm/trunk/lib/IR/DIBuilder.cpp
llvm/trunk/lib/IR/LLVMContextImpl.h
llvm/trunk/lib/IR/Verifier.cpp
llvm/trunk/unittests/IR/MetadataTest.cpp
Modified: llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfoMetadata.h?rev=233559&r1=233558&r2=233559&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Mon Mar 30 11:19:15 2015
@@ -998,12 +998,13 @@ class MDSubprogram : public MDLocalScope
static MDSubprogram *
getImpl(LLVMContext &Context, Metadata *Scope, StringRef Name,
- StringRef LinkageName, Metadata *File, unsigned Line, Metadata *Type,
- bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
- Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex,
- unsigned Flags, bool IsOptimized, Metadata *Function,
- Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables,
- StorageType Storage, bool ShouldCreate = true) {
+ StringRef LinkageName, MDFile *File, unsigned Line,
+ MDSubroutineType *Type, bool IsLocalToUnit, bool IsDefinition,
+ unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
+ unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
+ ConstantAsMetadata *Function, MDTuple *TemplateParams,
+ MDSubprogram *Declaration, MDTuple *Variables, StorageType Storage,
+ bool ShouldCreate = true) {
return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
getCanonicalMDString(Context, LinkageName), File, Line, Type,
IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
@@ -1032,12 +1033,13 @@ class MDSubprogram : public MDLocalScope
public:
DEFINE_MDNODE_GET(
MDSubprogram,
- (Metadata * Scope, StringRef Name, StringRef LinkageName, Metadata *File,
- unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
- unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality,
- unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
- Metadata *Function = nullptr, Metadata *TemplateParams = nullptr,
- Metadata *Declaration = nullptr, Metadata *Variables = nullptr),
+ (Metadata * Scope, StringRef Name, StringRef LinkageName, MDFile *File,
+ unsigned Line, MDSubroutineType *Type, bool IsLocalToUnit,
+ bool IsDefinition, unsigned ScopeLine, Metadata *ContainingType,
+ unsigned Virtuality, unsigned VirtualIndex, unsigned Flags,
+ bool IsOptimized, ConstantAsMetadata *Function = nullptr,
+ MDTuple *TemplateParams = nullptr, MDSubprogram *Declaration = nullptr,
+ MDTuple *Variables = nullptr),
(Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, IsDefinition,
ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
Function, TemplateParams, Declaration, Variables))
@@ -1065,7 +1067,10 @@ public:
bool isDefinition() const { return IsDefinition; }
bool isOptimized() const { return IsOptimized; }
- Metadata *getScope() const { return getOperand(1); }
+ // FIXME: Remove this once MDScope::getFile() does the same.
+ MDFile *getFile() const { return cast_or_null<MDFile>(getRawFile()); }
+
+ Metadata *getScope() const { return getRawScope(); }
StringRef getName() const { return getStringOperand(2); }
StringRef getDisplayName() const { return getStringOperand(3); }
@@ -1074,13 +1079,31 @@ public:
MDString *getRawName() const { return getOperandAs<MDString>(2); }
MDString *getRawLinkageName() const { return getOperandAs<MDString>(4); }
- Metadata *getType() const { return getOperand(5); }
- Metadata *getContainingType() const { return getOperand(6); }
+ MDSubroutineType *getType() const {
+ return cast_or_null<MDSubroutineType>(getRawType());
+ }
+ Metadata *getContainingType() const { return getRawContainingType(); }
+
+ ConstantAsMetadata *getFunction() const {
+ return cast_or_null<ConstantAsMetadata>(getRawFunction());
+ }
+ MDTuple *getTemplateParams() const {
+ return cast_or_null<MDTuple>(getRawTemplateParams());
+ }
+ MDSubprogram *getDeclaration() const {
+ return cast_or_null<MDSubprogram>(getRawDeclaration());
+ }
+ MDTuple *getVariables() const {
+ return cast_or_null<MDTuple>(getRawVariables());
+ }
- Metadata *getFunction() const { return getOperand(7); }
- Metadata *getTemplateParams() const { return getOperand(8); }
- Metadata *getDeclaration() const { return getOperand(9); }
- Metadata *getVariables() const { return getOperand(10); }
+ Metadata *getRawScope() const { return getOperand(1); }
+ Metadata *getRawType() const { return getOperand(5); }
+ Metadata *getRawContainingType() const { return getOperand(6); }
+ Metadata *getRawFunction() const { return getOperand(7); }
+ Metadata *getRawTemplateParams() const { return getOperand(8); }
+ Metadata *getRawDeclaration() const { return getOperand(9); }
+ Metadata *getRawVariables() const { return getOperand(10); }
/// \brief Replace the function.
///
Modified: llvm/trunk/lib/IR/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=233559&r1=233558&r2=233559&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AsmWriter.cpp (original)
+++ llvm/trunk/lib/IR/AsmWriter.cpp Mon Mar 30 11:19:15 2015
@@ -1629,23 +1629,23 @@ static void writeMDSubprogram(raw_ostrea
MDFieldPrinter Printer(Out, TypePrinter, Machine, Context);
Printer.printString("name", N->getName());
Printer.printString("linkageName", N->getLinkageName());
- Printer.printMetadata("scope", N->getScope(), /* ShouldSkipNull */ false);
- Printer.printMetadata("file", N->getFile());
+ Printer.printMetadata("scope", N->getRawScope(), /* ShouldSkipNull */ false);
+ Printer.printMetadata("file", N->getRawFile());
Printer.printInt("line", N->getLine());
- Printer.printMetadata("type", N->getType());
+ Printer.printMetadata("type", N->getRawType());
Printer.printBool("isLocal", N->isLocalToUnit());
Printer.printBool("isDefinition", N->isDefinition());
Printer.printInt("scopeLine", N->getScopeLine());
- Printer.printMetadata("containingType", N->getContainingType());
+ Printer.printMetadata("containingType", N->getRawContainingType());
Printer.printDwarfEnum("virtuality", N->getVirtuality(),
dwarf::VirtualityString);
Printer.printInt("virtualIndex", N->getVirtualIndex());
Printer.printDIFlags("flags", N->getFlags());
Printer.printBool("isOptimized", N->isOptimized());
- Printer.printMetadata("function", N->getFunction());
- Printer.printMetadata("templateParams", N->getTemplateParams());
- Printer.printMetadata("declaration", N->getDeclaration());
- Printer.printMetadata("variables", N->getVariables());
+ Printer.printMetadata("function", N->getRawFunction());
+ Printer.printMetadata("templateParams", N->getRawTemplateParams());
+ Printer.printMetadata("declaration", N->getRawDeclaration());
+ Printer.printMetadata("variables", N->getRawVariables());
Out << ")";
}
Modified: llvm/trunk/lib/IR/DIBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DIBuilder.cpp?rev=233559&r1=233558&r2=233559&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DIBuilder.cpp (original)
+++ llvm/trunk/lib/IR/DIBuilder.cpp Mon Mar 30 11:19:15 2015
@@ -674,9 +674,11 @@ DISubprogram DIBuilder::createFunction(D
"function types should be subroutines");
auto *Node = MDSubprogram::get(
VMContext, DIScope(getNonCompileUnitScope(Context)).getRef(), Name,
- LinkageName, File.getFileNode(), LineNo, Ty, isLocalToUnit, isDefinition,
- ScopeLine, nullptr, 0, 0, Flags, isOptimized, getConstantOrNull(Fn),
- TParams, Decl, MDNode::getTemporary(VMContext, None).release());
+ LinkageName, File.get(), LineNo, cast_or_null<MDSubroutineType>(Ty.get()),
+ isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized,
+ getConstantOrNull(Fn), cast_or_null<MDTuple>(TParams),
+ cast_or_null<MDSubprogram>(Decl),
+ MDTuple::getTemporary(VMContext, None).release());
if (isDefinition)
AllSubprograms.push_back(Node);
@@ -694,9 +696,11 @@ DIBuilder::createTempFunctionFwdDecl(DID
MDNode *TParams, MDNode *Decl) {
return MDSubprogram::getTemporary(
VMContext, DIScope(getNonCompileUnitScope(Context)).getRef(), Name,
- LinkageName, File.getFileNode(), LineNo, Ty, isLocalToUnit,
+ LinkageName, File.get(), LineNo,
+ cast_or_null<MDSubroutineType>(Ty.get()), isLocalToUnit,
isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized,
- getConstantOrNull(Fn), TParams, Decl, nullptr).release();
+ getConstantOrNull(Fn), cast_or_null<MDTuple>(TParams),
+ cast_or_null<MDSubprogram>(Decl), nullptr).release();
}
DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
@@ -714,10 +718,10 @@ DISubprogram DIBuilder::createMethod(DID
"the compile unit.");
// FIXME: Do we want to use different scope/lines?
auto *Node = MDSubprogram::get(
- VMContext, DIScope(Context).getRef(), Name, LinkageName, F.getFileNode(),
- LineNo, Ty, isLocalToUnit, isDefinition, LineNo, VTableHolder.getRef(),
- VK, VIndex, Flags, isOptimized, getConstantOrNull(Fn), TParam, nullptr,
- nullptr);
+ VMContext, DIScope(Context).getRef(), Name, LinkageName, F.get(), LineNo,
+ cast_or_null<MDSubroutineType>(Ty.get()), isLocalToUnit, isDefinition,
+ LineNo, VTableHolder.getRef(), VK, VIndex, Flags, isOptimized,
+ getConstantOrNull(Fn), cast_or_null<MDTuple>(TParam), nullptr, nullptr);
if (isDefinition)
AllSubprograms.push_back(Node);
Modified: llvm/trunk/lib/IR/LLVMContextImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContextImpl.h?rev=233559&r1=233558&r2=233559&view=diff
==============================================================================
--- llvm/trunk/lib/IR/LLVMContextImpl.h (original)
+++ llvm/trunk/lib/IR/LLVMContextImpl.h Mon Mar 30 11:19:15 2015
@@ -550,31 +550,32 @@ template <> struct MDNodeKeyImpl<MDSubpr
Function(Function), TemplateParams(TemplateParams),
Declaration(Declaration), Variables(Variables) {}
MDNodeKeyImpl(const MDSubprogram *N)
- : Scope(N->getScope()), Name(N->getName()),
- LinkageName(N->getLinkageName()), File(N->getFile()),
- Line(N->getLine()), Type(N->getType()),
+ : Scope(N->getRawScope()), Name(N->getName()),
+ LinkageName(N->getLinkageName()), File(N->getRawFile()),
+ Line(N->getLine()), Type(N->getRawType()),
IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
- ScopeLine(N->getScopeLine()), ContainingType(N->getContainingType()),
+ ScopeLine(N->getScopeLine()), ContainingType(N->getRawContainingType()),
Virtuality(N->getVirtuality()), VirtualIndex(N->getVirtualIndex()),
Flags(N->getFlags()), IsOptimized(N->isOptimized()),
- Function(N->getFunction()), TemplateParams(N->getTemplateParams()),
- Declaration(N->getDeclaration()), Variables(N->getVariables()) {}
+ Function(N->getRawFunction()),
+ TemplateParams(N->getRawTemplateParams()),
+ Declaration(N->getRawDeclaration()), Variables(N->getRawVariables()) {}
bool isKeyOf(const MDSubprogram *RHS) const {
- return Scope == RHS->getScope() && Name == RHS->getName() &&
- LinkageName == RHS->getLinkageName() && File == RHS->getFile() &&
- Line == RHS->getLine() && Type == RHS->getType() &&
+ return Scope == RHS->getRawScope() && Name == RHS->getName() &&
+ LinkageName == RHS->getLinkageName() && File == RHS->getRawFile() &&
+ Line == RHS->getLine() && Type == RHS->getRawType() &&
IsLocalToUnit == RHS->isLocalToUnit() &&
IsDefinition == RHS->isDefinition() &&
ScopeLine == RHS->getScopeLine() &&
- ContainingType == RHS->getContainingType() &&
+ ContainingType == RHS->getRawContainingType() &&
Virtuality == RHS->getVirtuality() &&
VirtualIndex == RHS->getVirtualIndex() && Flags == RHS->getFlags() &&
IsOptimized == RHS->isOptimized() &&
- Function == RHS->getFunction() &&
- TemplateParams == RHS->getTemplateParams() &&
- Declaration == RHS->getDeclaration() &&
- Variables == RHS->getVariables();
+ Function == RHS->getRawFunction() &&
+ TemplateParams == RHS->getRawTemplateParams() &&
+ Declaration == RHS->getRawDeclaration() &&
+ Variables == RHS->getRawVariables();
}
unsigned getHashValue() const {
return hash_combine(Scope, Name, LinkageName, File, Line, Type,
Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=233559&r1=233558&r2=233559&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Mon Mar 30 11:19:15 2015
@@ -296,6 +296,7 @@ private:
void visitBasicBlock(BasicBlock &BB);
void visitRangeMetadata(Instruction& I, MDNode* Range, Type* Ty);
+ template <class Ty> bool isValidMetadataArray(const MDTuple &N);
#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) void visit##CLASS(const CLASS &N);
#include "llvm/IR/Metadata.def"
void visitMDScope(const MDScope &N);
@@ -679,6 +680,30 @@ static bool isScopeRef(const Metadata *M
return isa<MDScope>(MD);
}
+template <class Ty>
+bool isValidMetadataArrayImpl(const MDTuple &N, bool AllowNull) {
+ for (Metadata *MD : N.operands()) {
+ if (MD) {
+ if (!isa<Ty>(MD))
+ return false;
+ } else {
+ if (!AllowNull)
+ return false;
+ }
+ }
+ return true;
+}
+
+template <class Ty>
+bool isValidMetadataArray(const MDTuple &N) {
+ return isValidMetadataArrayImpl<Ty>(N, /* AllowNull */ false);
+}
+
+template <class Ty>
+bool isValidMetadataNullArray(const MDTuple &N) {
+ return isValidMetadataArrayImpl<Ty>(N, /* AllowNull */ true);
+}
+
void Verifier::visitMDLocation(const MDLocation &N) {
Assert(N.getRawScope() && isa<MDLocalScope>(N.getRawScope()),
"location requires a valid scope", &N, N.getRawScope());
@@ -811,6 +836,39 @@ void Verifier::visitMDCompileUnit(const
void Verifier::visitMDSubprogram(const MDSubprogram &N) {
Assert(N.getTag() == dwarf::DW_TAG_subprogram, "invalid tag", &N);
+ Assert(isScopeRef(N.getRawScope()), "invalid scope", &N, N.getRawScope());
+ if (auto *T = N.getRawType())
+ Assert(isa<MDSubroutineType>(T), "invalid subroutine type", &N, T);
+ Assert(isTypeRef(N.getRawContainingType()), "invalid containing type", &N,
+ N.getRawContainingType());
+ if (auto *RawF = N.getRawFunction()) {
+ auto *FMD = dyn_cast<ConstantAsMetadata>(RawF);
+ auto *F = FMD ? FMD->getValue() : nullptr;
+ auto *FT = F ? dyn_cast<PointerType>(F->getType()) : nullptr;
+ Assert(F && (isa<Function>(F) || isa<ConstantPointerNull>(F)) && FT &&
+ isa<FunctionType>(FT->getElementType()),
+ "invalid function", &N, F);
+ }
+ if (N.getRawTemplateParams()) {
+ auto *Params = dyn_cast<MDTuple>(N.getRawTemplateParams());
+ Assert(Params, "invalid template params", &N, Params);
+ for (Metadata *Op : Params->operands()) {
+ Assert(Op && isa<MDTemplateParameter>(Op), "invalid template parameter",
+ &N, Params, Op);
+ }
+ }
+ if (auto *S = N.getRawDeclaration()) {
+ Assert(isa<MDSubprogram>(S) && !cast<MDSubprogram>(S)->isDefinition(),
+ "invalid subprogram declaration", &N, S);
+ }
+ if (N.getRawVariables()) {
+ auto *Vars = dyn_cast<MDTuple>(N.getRawVariables());
+ Assert(Vars, "invalid variable list", &N, Vars);
+ for (Metadata *Op : Vars->operands()) {
+ Assert(Op && isa<MDLocalVariable>(Op), "invalid local variable", &N, Vars,
+ Op);
+ }
+ }
}
void Verifier::visitMDLexicalBlock(const MDLexicalBlock &N) {
Modified: llvm/trunk/unittests/IR/MetadataTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/MetadataTest.cpp?rev=233559&r1=233558&r2=233559&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/MetadataTest.cpp (original)
+++ llvm/trunk/unittests/IR/MetadataTest.cpp Mon Mar 30 11:19:15 2015
@@ -62,10 +62,11 @@ TEST(ContextAndReplaceableUsesTest, take
class MetadataTest : public testing::Test {
public:
- MetadataTest() : Counter(0) {}
+ MetadataTest() : M("test", Context), Counter(0) {}
protected:
LLVMContext Context;
+ Module M;
int Counter;
MDNode *getNode() { return MDNode::get(Context, None); }
@@ -76,6 +77,9 @@ protected:
}
MDTuple *getTuple() { return MDTuple::getDistinct(Context, None); }
+ MDSubroutineType *getSubroutineType() {
+ return MDSubroutineType::getDistinct(Context, 0, getNode(nullptr));
+ }
MDSubprogram *getSubprogram() {
return MDSubprogram::getDistinct(Context, nullptr, "", "", nullptr, 0,
nullptr, false, false, 0, nullptr, 0, 0, 0,
@@ -101,6 +105,10 @@ protected:
Context, dwarf::DW_TAG_structure_type, "", nullptr, 0, nullptr, nullptr,
32, 32, 0, 0, nullptr, 0, nullptr, nullptr, "");
}
+ ConstantAsMetadata *getFunctionAsMetadata(StringRef Name) {
+ return ConstantAsMetadata::get(M.getOrInsertFunction(
+ Name, FunctionType::get(Type::getVoidTy(Context), None, false)));
+ }
};
typedef MetadataTest MDStringTest;
@@ -1363,24 +1371,24 @@ TEST_F(MDCompileUnitTest, replaceArrays)
typedef MetadataTest MDSubprogramTest;
TEST_F(MDSubprogramTest, get) {
- Metadata *Scope = MDTuple::getDistinct(Context, None);
+ MDScope *Scope = getCompositeType();
StringRef Name = "name";
StringRef LinkageName = "linkage";
- Metadata *File = MDTuple::getDistinct(Context, None);
+ MDFile *File = getFile();
unsigned Line = 2;
- Metadata *Type = MDTuple::getDistinct(Context, None);
+ MDSubroutineType *Type = getSubroutineType();
bool IsLocalToUnit = false;
bool IsDefinition = true;
unsigned ScopeLine = 3;
- Metadata *ContainingType = MDTuple::getDistinct(Context, None);
+ MDType *ContainingType = getCompositeType();
unsigned Virtuality = 4;
unsigned VirtualIndex = 5;
unsigned Flags = 6;
bool IsOptimized = false;
- Metadata *Function = MDTuple::getDistinct(Context, None);
- Metadata *TemplateParams = MDTuple::getDistinct(Context, None);
- Metadata *Declaration = MDTuple::getDistinct(Context, None);
- Metadata *Variables = MDTuple::getDistinct(Context, None);
+ ConstantAsMetadata *Function = getFunctionAsMetadata("foo");
+ MDTuple *TemplateParams = getTuple();
+ MDSubprogram *Declaration = getSubprogram();
+ MDTuple *Variables = getTuple();
auto *N = MDSubprogram::get(
Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
@@ -1412,11 +1420,11 @@ TEST_F(MDSubprogramTest, get) {
Flags, IsOptimized, Function, TemplateParams,
Declaration, Variables));
- EXPECT_NE(N, MDSubprogram::get(Context, File, Name, LinkageName, File, Line,
- Type, IsLocalToUnit, IsDefinition, ScopeLine,
- ContainingType, Virtuality, VirtualIndex,
- Flags, IsOptimized, Function, TemplateParams,
- Declaration, Variables));
+ EXPECT_NE(N, MDSubprogram::get(Context, getCompositeType(), Name, LinkageName,
+ File, Line, Type, IsLocalToUnit, IsDefinition,
+ ScopeLine, ContainingType, Virtuality,
+ VirtualIndex, Flags, IsOptimized, Function,
+ TemplateParams, Declaration, Variables));
EXPECT_NE(N, MDSubprogram::get(Context, Scope, "other", LinkageName, File,
Line, Type, IsLocalToUnit, IsDefinition,
ScopeLine, ContainingType, Virtuality,
@@ -1427,21 +1435,21 @@ TEST_F(MDSubprogramTest, get) {
ContainingType, Virtuality, VirtualIndex,
Flags, IsOptimized, Function, TemplateParams,
Declaration, Variables));
- EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, Scope, Line,
- Type, IsLocalToUnit, IsDefinition, ScopeLine,
- ContainingType, Virtuality, VirtualIndex,
- Flags, IsOptimized, Function, TemplateParams,
- Declaration, Variables));
+ EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, getFile(),
+ Line, Type, IsLocalToUnit, IsDefinition,
+ ScopeLine, ContainingType, Virtuality,
+ VirtualIndex, Flags, IsOptimized, Function,
+ TemplateParams, Declaration, Variables));
EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File,
Line + 1, Type, IsLocalToUnit, IsDefinition,
ScopeLine, ContainingType, Virtuality,
VirtualIndex, Flags, IsOptimized, Function,
TemplateParams, Declaration, Variables));
- EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
- Scope, IsLocalToUnit, IsDefinition, ScopeLine,
- ContainingType, Virtuality, VirtualIndex,
- Flags, IsOptimized, Function, TemplateParams,
- Declaration, Variables));
+ EXPECT_NE(N, MDSubprogram::get(
+ Context, Scope, Name, LinkageName, File, Line,
+ getSubroutineType(), IsLocalToUnit, IsDefinition, ScopeLine,
+ ContainingType, Virtuality, VirtualIndex, Flags, IsOptimized,
+ Function, TemplateParams, Declaration, Variables));
EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
Type, !IsLocalToUnit, IsDefinition, ScopeLine,
ContainingType, Virtuality, VirtualIndex,
@@ -1459,8 +1467,8 @@ TEST_F(MDSubprogramTest, get) {
TemplateParams, Declaration, Variables));
EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
Type, IsLocalToUnit, IsDefinition, ScopeLine,
- Type, Virtuality, VirtualIndex, Flags,
- IsOptimized, Function, TemplateParams,
+ getCompositeType(), Virtuality, VirtualIndex,
+ Flags, IsOptimized, Function, TemplateParams,
Declaration, Variables));
EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
Type, IsLocalToUnit, IsDefinition, ScopeLine,
@@ -1482,49 +1490,50 @@ TEST_F(MDSubprogramTest, get) {
ContainingType, Virtuality, VirtualIndex,
Flags, !IsOptimized, Function, TemplateParams,
Declaration, Variables));
+ EXPECT_NE(N,
+ MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
+ Type, IsLocalToUnit, IsDefinition, ScopeLine,
+ ContainingType, Virtuality, VirtualIndex, Flags,
+ IsOptimized, getFunctionAsMetadata("bar"),
+ TemplateParams, Declaration, Variables));
EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
Type, IsLocalToUnit, IsDefinition, ScopeLine,
ContainingType, Virtuality, VirtualIndex,
- Flags, IsOptimized, Type, TemplateParams,
- Declaration, Variables));
- EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
- Type, IsLocalToUnit, IsDefinition, ScopeLine,
- ContainingType, Virtuality, VirtualIndex,
- Flags, IsOptimized, Function, Type,
+ Flags, IsOptimized, Function, getTuple(),
Declaration, Variables));
EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
Type, IsLocalToUnit, IsDefinition, ScopeLine,
ContainingType, Virtuality, VirtualIndex,
Flags, IsOptimized, Function, TemplateParams,
- Type, Variables));
+ getSubprogram(), Variables));
EXPECT_NE(N, MDSubprogram::get(Context, Scope, Name, LinkageName, File, Line,
Type, IsLocalToUnit, IsDefinition, ScopeLine,
ContainingType, Virtuality, VirtualIndex,
Flags, IsOptimized, Function, TemplateParams,
- Declaration, Type));
+ Declaration, getTuple()));
TempMDSubprogram Temp = N->clone();
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
}
TEST_F(MDSubprogramTest, replaceFunction) {
- Metadata *Scope = MDTuple::getDistinct(Context, None);
+ MDScope *Scope = getCompositeType();
StringRef Name = "name";
StringRef LinkageName = "linkage";
- Metadata *File = MDTuple::getDistinct(Context, None);
+ MDFile *File = getFile();
unsigned Line = 2;
- Metadata *Type = MDTuple::getDistinct(Context, None);
+ MDSubroutineType *Type = getSubroutineType();
bool IsLocalToUnit = false;
bool IsDefinition = true;
unsigned ScopeLine = 3;
- Metadata *ContainingType = MDTuple::getDistinct(Context, None);
+ MDCompositeType *ContainingType = getCompositeType();
unsigned Virtuality = 4;
unsigned VirtualIndex = 5;
unsigned Flags = 6;
bool IsOptimized = false;
- Metadata *TemplateParams = MDTuple::getDistinct(Context, None);
- Metadata *Declaration = MDTuple::getDistinct(Context, None);
- Metadata *Variables = MDTuple::getDistinct(Context, None);
+ MDTuple *TemplateParams = getTuple();
+ MDSubprogram *Declaration = getSubprogram();
+ MDTuple *Variables = getTuple();
auto *N = MDSubprogram::get(
Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
More information about the llvm-commits
mailing list