IR: Make temporary nodes distinct
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 12 Jan 2015 18:41:26 +0000 (18:41 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 12 Jan 2015 18:41:26 +0000 (18:41 +0000)
Change the return of `MDNode::isDistinct()` for `MDNode::getTemporary()`
to `true`.  They aren't uniqued.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225646 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/Metadata.h
unittests/IR/MetadataTest.cpp

index 75c9734ea97d5a11530ea146238785405787ebae..4d0a04ea62336eb6037b219f33b3160a591e72ee 100644 (file)
@@ -651,7 +651,9 @@ public:
   ///
   /// Distinct nodes are not uniqued, and will not be returned by \a
   /// MDNode::get().
-  bool isDistinct() const { return IsDistinctInContext; }
+  bool isDistinct() const {
+    return isStoredDistinctInContext() || isa<MDNodeFwdDecl>(this);
+  }
 
 protected:
   /// \brief Set an operand.
index 2dd54e785bfdac8f8975e031b955589bd2c5628a..a09cc9cfd7d81430e2b23b69f1d328d7c3fcb40c 100644 (file)
@@ -269,6 +269,12 @@ TEST_F(MDNodeTest, getDistinct) {
   ASSERT_EQ(Empty, MDNode::get(Context, None));
 }
 
+TEST_F(MDNodeTest, TempIsDistinct) {
+  MDNode *T = MDNode::getTemporary(Context, None);
+  EXPECT_TRUE(T->isDistinct());
+  MDNode::deleteTemporary(T);
+}
+
 TEST_F(MDNodeTest, getDistinctWithUnresolvedOperands) {
   // temporary !{}
   MDNodeFwdDecl *Temp = MDNode::getTemporary(Context, None);