[llvm-commits] [llvm] r153798 - in /llvm/trunk: lib/VMCore/Metadata.cpp unittests/VMCore/MetadataTest.cpp
Duncan Sands
baldrick at free.fr
Sat Mar 31 01:20:12 PDT 2012
Author: baldrick
Date: Sat Mar 31 03:20:11 2012
New Revision: 153798
URL: http://llvm.org/viewvc/llvm-project?rev=153798&view=rev
Log:
I noticed in passing that the Metadata getIfExists method was creating a new
node and returning it if one didn't exist.
Modified:
llvm/trunk/lib/VMCore/Metadata.cpp
llvm/trunk/unittests/VMCore/MetadataTest.cpp
Modified: llvm/trunk/lib/VMCore/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Metadata.cpp?rev=153798&r1=153797&r2=153798&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Metadata.cpp (original)
+++ llvm/trunk/lib/VMCore/Metadata.cpp Sat Mar 31 03:20:11 2012
@@ -205,11 +205,11 @@
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:
Modified: llvm/trunk/unittests/VMCore/MetadataTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/VMCore/MetadataTest.cpp?rev=153798&r1=153797&r2=153798&view=diff
==============================================================================
--- llvm/trunk/unittests/VMCore/MetadataTest.cpp (original)
+++ llvm/trunk/unittests/VMCore/MetadataTest.cpp Sat Mar 31 03:20:11 2012
@@ -90,13 +90,20 @@
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));
More information about the llvm-commits
mailing list