diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-02-18 20:32:57 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-02-18 20:32:57 +0000 |
commit | df52349bb07133cb8a7adbb80c4b764591d70cf2 (patch) | |
tree | 3426978cb02e891f26963c33c0b429635ebf8358 /llvm/unittests/IR/MetadataTest.cpp | |
parent | 6fbde1f9975cfed12951faee633a089a6fbd87f6 (diff) | |
download | bcm5719-llvm-df52349bb07133cb8a7adbb80c4b764591d70cf2.tar.gz bcm5719-llvm-df52349bb07133cb8a7adbb80c4b764591d70cf2.zip |
IR: Add MDSubprogram::replaceFunction()
llvm-svn: 229742
Diffstat (limited to 'llvm/unittests/IR/MetadataTest.cpp')
-rw-r--r-- | llvm/unittests/IR/MetadataTest.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/llvm/unittests/IR/MetadataTest.cpp b/llvm/unittests/IR/MetadataTest.cpp index 31a71473507..db06fb62fa1 100644 --- a/llvm/unittests/IR/MetadataTest.cpp +++ b/llvm/unittests/IR/MetadataTest.cpp @@ -10,6 +10,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DebugInfoMetadata.h" +#include "llvm/IR/Function.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Metadata.h" @@ -1189,6 +1190,42 @@ TEST_F(MDSubprogramTest, get) { EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); } +TEST_F(MDSubprogramTest, replaceFunction) { + Metadata *Scope = MDTuple::getDistinct(Context, None); + StringRef Name = "name"; + StringRef LinkageName = "linkage"; + Metadata *File = MDTuple::getDistinct(Context, None); + unsigned Line = 2; + Metadata *Type = MDTuple::getDistinct(Context, None); + bool IsLocalToUnit = false; + bool IsDefinition = true; + unsigned ScopeLine = 3; + Metadata *ContainingType = MDTuple::getDistinct(Context, None); + 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); + + auto *N = MDSubprogram::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(ConstantAsMetadata::get(F.get()), N->getFunction()); + + N->replaceFunction(nullptr); + EXPECT_EQ(nullptr, N->getFunction()); +} + typedef MetadataTest MDLexicalBlockTest; TEST_F(MDLexicalBlockTest, get) { |