diff --git a/llvm/include/llvm/IR/Metadata.h b/llvm/include/llvm/IR/Metadata.h index 75c9734ea97d5a11530ea146238785405787ebae..4d0a04ea62336eb6037b219f33b3160a591e72ee 100644 --- a/llvm/include/llvm/IR/Metadata.h +++ b/llvm/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/llvm/unittests/IR/MetadataTest.cpp b/llvm/unittests/IR/MetadataTest.cpp index 2dd54e785bfdac8f8975e031b955589bd2c5628a..a09cc9cfd7d81430e2b23b69f1d328d7c3fcb40c 100644 --- a/llvm/unittests/IR/MetadataTest.cpp +++ b/llvm/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);