aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/IR/MetadataTest.cpp
diff options
context:
space:
mode:
authorWolfgang Pieb <wolfgang_pieb@playstation.sony.com>2022-05-23 17:08:01 -0700
committerWolfgang Pieb <wolfgang_pieb@playstation.sony.com>2022-05-23 20:04:45 -0700
commitae9489025f1a8021e57a61e79666558ca17afd68 (patch)
tree9cdc4a344883505eb4272ea2ef4401a98847340d /llvm/unittests/IR/MetadataTest.cpp
parentd7ebb7461151fdb8dcf00a9a01d484355a0c6074 (diff)
downloadllvm-ae9489025f1a8021e57a61e79666558ca17afd68.zip
llvm-ae9489025f1a8021e57a61e79666558ca17afd68.tar.gz
llvm-ae9489025f1a8021e57a61e79666558ca17afd68.tar.bz2
[NFC][Metadata] Define move constructor and move assignment operator for MDOperand.
This is a preparatory patch for the MDNode resize functionality. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D125994
Diffstat (limited to 'llvm/unittests/IR/MetadataTest.cpp')
-rw-r--r--llvm/unittests/IR/MetadataTest.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/llvm/unittests/IR/MetadataTest.cpp b/llvm/unittests/IR/MetadataTest.cpp
index 4297e32..41ea3e9 100644
--- a/llvm/unittests/IR/MetadataTest.cpp
+++ b/llvm/unittests/IR/MetadataTest.cpp
@@ -3602,4 +3602,33 @@ TEST_F(DebugVariableTest, DenseMap) {
EXPECT_EQ(DebugVariableMap.find(DebugVariableFragB)->second, 12u);
}
+typedef MetadataTest MDTupleAllocationTest;
+TEST_F(MDTupleAllocationTest, Tracking) {
+ // Make sure that the move constructor and move assignment op
+ // for MDOperand correctly adjust tracking information.
+ auto *Value1 = getConstantAsMetadata();
+ MDTuple *A = MDTuple::getDistinct(Context, {Value1, Value1});
+ EXPECT_EQ(A->getOperand(0), Value1);
+ EXPECT_EQ(A->getOperand(1), Value1);
+
+ MDNode::op_range Ops = A->operands();
+
+ MDOperand NewOps1;
+ // Move assignment operator.
+ NewOps1 = std::move(*const_cast<MDOperand *>(Ops.begin()));
+ // Move constructor.
+ MDOperand NewOps2(std::move(*const_cast<MDOperand *>(Ops.begin() + 1)));
+
+ EXPECT_EQ(NewOps1.get(), static_cast<Metadata *>(Value1));
+ EXPECT_EQ(NewOps2.get(), static_cast<Metadata *>(Value1));
+
+ auto *Value2 = getConstantAsMetadata();
+ Value *V1 = Value1->getValue();
+ Value *V2 = Value2->getValue();
+ ValueAsMetadata::handleRAUW(V1, V2);
+
+ EXPECT_EQ(NewOps1.get(), static_cast<Metadata *>(Value2));
+ EXPECT_EQ(NewOps2.get(), static_cast<Metadata *>(Value2));
+}
+
} // end namespace