diff options
author | Duncan Sands <baldrick@free.fr> | 2012-03-31 08:20:11 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2012-03-31 08:20:11 +0000 |
commit | 4000afe712a7fd9e584919c43d2aa09b154946c1 (patch) | |
tree | 572dfb270d80445cbe485214698cb258a11c52ba | |
parent | 6173ed95daf2f209fe3883faee45967e4800ae75 (diff) |
I noticed in passing that the Metadata getIfExists method was creating a new
node and returning it if one didn't exist.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153798 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/VMCore/Metadata.cpp | 8 | ||||
-rw-r--r-- | unittests/VMCore/MetadataTest.cpp | 7 |
2 files changed, 11 insertions, 4 deletions
diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp index 0fc2a2534d..e3a08d4949 100644 --- a/lib/VMCore/Metadata.cpp +++ b/lib/VMCore/Metadata.cpp @@ -205,11 +205,11 @@ MDNode *MDNode::getMDNode(LLVMContext &Context, ArrayRef<Value*> Vals, ID.AddPointer(Vals[i]); void *InsertPoint; - MDNode *N = NULL; - - if ((N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint))) + MDNode *N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint); + + if (N || !Insert) return N; - + bool isFunctionLocal = false; switch (FL) { case FL_Unknown: diff --git a/unittests/VMCore/MetadataTest.cpp b/unittests/VMCore/MetadataTest.cpp index 12ac2e704c..08927a2ff5 100644 --- a/unittests/VMCore/MetadataTest.cpp +++ b/unittests/VMCore/MetadataTest.cpp @@ -90,13 +90,20 @@ TEST_F(MDNodeTest, Simple) { MDNode *n1 = MDNode::get(Context, V); Value *const c1 = n1; MDNode *n2 = MDNode::get(Context, c1); + Value *const c2 = n2; MDNode *n3 = MDNode::get(Context, V); + MDNode *n4 = MDNode::getIfExists(Context, V); + MDNode *n5 = MDNode::getIfExists(Context, c1); + MDNode *n6 = MDNode::getIfExists(Context, c2); EXPECT_NE(n1, n2); #ifdef ENABLE_MDNODE_UNIQUING EXPECT_EQ(n1, n3); #else (void) n3; #endif + EXPECT_EQ(n4, n1); + EXPECT_EQ(n5, n2); + EXPECT_EQ(n6, (Value*)0); EXPECT_EQ(3u, n1->getNumOperands()); EXPECT_EQ(s1, n1->getOperand(0)); |