diff --git a/include/llvm/IR/Metadata.h b/include/llvm/IR/Metadata.h index 75c9734ea97..4d0a04ea623 100644 --- a/include/llvm/IR/Metadata.h +++ b/include/llvm/IR/Metadata.h @@ -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(this); + } protected: /// \brief Set an operand. diff --git a/unittests/IR/MetadataTest.cpp b/unittests/IR/MetadataTest.cpp index 2dd54e785bf..a09cc9cfd7d 100644 --- a/unittests/IR/MetadataTest.cpp +++ b/unittests/IR/MetadataTest.cpp @@ -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);