summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp')
-rw-r--r--gnu/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/gnu/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp b/gnu/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp
new file mode 100644
index 00000000000..9dbe4dbc56d
--- /dev/null
+++ b/gnu/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp
@@ -0,0 +1,58 @@
+//===- ValueMapper.cpp - Unit tests for ValueMapper -----------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Metadata.h"
+#include "llvm/Transforms/Utils/ValueMapper.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+TEST(ValueMapperTest, MapMetadataUnresolved) {
+ LLVMContext Context;
+ TempMDTuple T = MDTuple::getTemporary(Context, None);
+
+ ValueToValueMapTy VM;
+ EXPECT_EQ(T.get(), MapMetadata(T.get(), VM, RF_NoModuleLevelChanges));
+}
+
+TEST(ValueMapperTest, MapMetadataDistinct) {
+ LLVMContext Context;
+ auto *D = MDTuple::getDistinct(Context, None);
+
+ {
+ // The node should be cloned.
+ ValueToValueMapTy VM;
+ EXPECT_NE(D, MapMetadata(D, VM, RF_None));
+ }
+ {
+ // The node should be moved.
+ ValueToValueMapTy VM;
+ EXPECT_EQ(D, MapMetadata(D, VM, RF_MoveDistinctMDs));
+ }
+}
+
+TEST(ValueMapperTest, MapMetadataDistinctOperands) {
+ LLVMContext Context;
+ Metadata *Old = MDTuple::getDistinct(Context, None);
+ auto *D = MDTuple::getDistinct(Context, Old);
+ ASSERT_EQ(Old, D->getOperand(0));
+
+ Metadata *New = MDTuple::getDistinct(Context, None);
+ ValueToValueMapTy VM;
+ VM.MD()[Old].reset(New);
+
+ // Make sure operands are updated.
+ EXPECT_EQ(D, MapMetadata(D, VM, RF_MoveDistinctMDs));
+ EXPECT_EQ(New, D->getOperand(0));
+}
+
+}