diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-13 00:10:38 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-13 00:10:38 +0000 |
commit | e4c842f8163022324ad2372904c6ad9ac250a963 (patch) | |
tree | 3a3b3e456cf830f3069e14fe78f8c4d3870a05a2 /llvm/unittests/IR/MetadataTest.cpp | |
parent | 427e1214b44b6fb3110119db7d9d3018eecb770f (diff) | |
download | bcm5719-llvm-e4c842f8163022324ad2372904c6ad9ac250a963.tar.gz bcm5719-llvm-e4c842f8163022324ad2372904c6ad9ac250a963.zip |
IR: Fix an inverted assertion when replacing resolved operands
Add a unit test, since this bug was only exposed by clang tests. Thanks
to Rafael for tracking this down!
llvm-svn: 225738
Diffstat (limited to 'llvm/unittests/IR/MetadataTest.cpp')
-rw-r--r-- | llvm/unittests/IR/MetadataTest.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/unittests/IR/MetadataTest.cpp b/llvm/unittests/IR/MetadataTest.cpp index af110742dd7..c364aeacba1 100644 --- a/llvm/unittests/IR/MetadataTest.cpp +++ b/llvm/unittests/IR/MetadataTest.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/STLExtras.h" #include "llvm/IR/Metadata.h" #include "llvm/IR/Constants.h" #include "llvm/IR/Instructions.h" @@ -361,6 +362,28 @@ TEST_F(MDNodeTest, handleChangedOperandRecursion) { EXPECT_EQ(N4, N6->getOperand(0)); } +TEST_F(MDNodeTest, replaceResolvedOperand) { + // Check code for replacing one resolved operand with another. If doing this + // directly (via replaceOperandWith()) becomes illegal, change the operand to + // a global value that gets RAUW'ed. + // + // Use a temporary node to keep N from being resolved. + std::unique_ptr<MDNodeFwdDecl> Temp(MDNodeFwdDecl::get(Context, None)); + Metadata *Ops[] = {nullptr, Temp.get()}; + + MDNode *Empty = MDTuple::get(Context, {}); + MDNode *N = MDTuple::get(Context, Ops); + EXPECT_EQ(nullptr, N->getOperand(0)); + ASSERT_FALSE(N->isResolved()); + + // Check code for replacing resolved nodes. + N->replaceOperandWith(0, Empty); + EXPECT_EQ(Empty, N->getOperand(0)); + + // Remove the reference to Temp; required for teardown. + N->replaceOperandWith(1, nullptr); +} + typedef MetadataTest MetadataAsValueTest; TEST_F(MetadataAsValueTest, MDNode) { |