]> granicus.if.org Git - llvm/commitdiff
[unittests] Adding a unittest for ChangeTaTargetIndex. NFC
authorMarcello Maggioni <hayarms@gmail.com>
Thu, 10 Aug 2017 15:35:25 +0000 (15:35 +0000)
committerMarcello Maggioni <hayarms@gmail.com>
Thu, 10 Aug 2017 15:35:25 +0000 (15:35 +0000)
Differential Revision: https://reviews.llvm.org/D36565

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310610 91177308-0d34-0410-b5e6-96231b3b80d8

unittests/CodeGen/CMakeLists.txt
unittests/CodeGen/MachineOperandTest.cpp [new file with mode: 0644]

index e944f6c9e3b99f029f53bfc1599fe6a072dc96d6..8ee714dc78ffe92a83b6202218608bf3c4e5e13d 100644 (file)
@@ -9,6 +9,7 @@ set(CodeGenSources
   DIEHashTest.cpp
   LowLevelTypeTest.cpp
   MachineInstrBundleIteratorTest.cpp
+  MachineOperandTest.cpp
   ScalableVectorMVTsTest.cpp
   )
 
diff --git a/unittests/CodeGen/MachineOperandTest.cpp b/unittests/CodeGen/MachineOperandTest.cpp
new file mode 100644 (file)
index 0000000..afbf4f4
--- /dev/null
@@ -0,0 +1,40 @@
+//===- MachineOperandTest.cpp ---------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/ilist_node.h"
+#include "llvm/CodeGen/MachineOperand.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+TEST(MachineOperandTest, ChangeToTargetIndexTest) {
+  // Creating a MachineOperand to change it to TargetIndex
+  MachineOperand MO = MachineOperand::CreateImm(50);
+
+  // Checking some precondition on the newly created
+  // MachineOperand.
+  ASSERT_TRUE(MO.isImm());
+  ASSERT_TRUE(MO.getImm() == 50);
+  ASSERT_FALSE(MO.isTargetIndex());
+
+  // Changing to TargetIndex with some arbitrary values
+  // for index, offset and flags.
+  MO.ChangeToTargetIndex(74, 57, 12);
+
+  // Checking that the mutation to TargetIndex happened
+  // correctly.
+  ASSERT_TRUE(MO.isTargetIndex());
+  ASSERT_TRUE(MO.getIndex() == 74);
+  ASSERT_TRUE(MO.getOffset() == 57);
+  ASSERT_TRUE(MO.getTargetFlags() == 12);
+}
+
+} // end namespace