aboutsummaryrefslogtreecommitdiffstats
path: root/unittests/VMCore/InstructionsTest.cpp
diff options
context:
space:
mode:
authorGabor Greif <ggreif@gmail.com>2010-03-16 15:26:09 +0000
committerGabor Greif <ggreif@gmail.com>2010-03-16 15:26:09 +0000
commitd165e1a71193ebff49ede9663d1ed70050f04699 (patch)
tree81c9cf385132577c8281a1b05429db5697161c1d /unittests/VMCore/InstructionsTest.cpp
parent642c066906488715220dd87c5b976c67bb8a303d (diff)
downloadexternal_llvm-d165e1a71193ebff49ede9663d1ed70050f04699.zip
external_llvm-d165e1a71193ebff49ede9663d1ed70050f04699.tar.gz
external_llvm-d165e1a71193ebff49ede9663d1ed70050f04699.tar.bz2
add BranchInst tests
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98632 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/VMCore/InstructionsTest.cpp')
-rw-r--r--unittests/VMCore/InstructionsTest.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/unittests/VMCore/InstructionsTest.cpp b/unittests/VMCore/InstructionsTest.cpp
index 2d98cad..800511e 100644
--- a/unittests/VMCore/InstructionsTest.cpp
+++ b/unittests/VMCore/InstructionsTest.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Instructions.h"
+#include "llvm/BasicBlock.h"
#include "llvm/DerivedTypes.h"
#include "llvm/LLVMContext.h"
#include "gtest/gtest.h"
@@ -20,11 +21,13 @@ TEST(InstructionsTest, ReturnInst) {
// test for PR6589
const ReturnInst* r0 = ReturnInst::Create(C);
+ EXPECT_EQ(r0->getNumOperands(), 0U);
EXPECT_EQ(r0->op_begin(), r0->op_end());
const IntegerType* Int1 = IntegerType::get(C, 1);
Constant* One = ConstantInt::get(Int1, 1, true);
const ReturnInst* r1 = ReturnInst::Create(C, One);
+ EXPECT_EQ(r1->getNumOperands(), 1U);
User::const_op_iterator b(r1->op_begin());
EXPECT_NE(b, r1->op_end());
EXPECT_EQ(*b, One);
@@ -37,5 +40,73 @@ TEST(InstructionsTest, ReturnInst) {
delete r1;
}
+TEST(InstructionsTest, BranchInst) {
+ LLVMContext &C(getGlobalContext());
+
+ // Make a BasicBlocks
+ BasicBlock* bb0 = BasicBlock::Create(C);
+ BasicBlock* bb1 = BasicBlock::Create(C);
+
+ // Mandatory BranchInst
+ const BranchInst* b0 = BranchInst::Create(bb0);
+
+ // check num operands
+ EXPECT_EQ(b0->getNumOperands(), 1U);
+
+ EXPECT_NE(b0->op_begin(), b0->op_end());
+
+ const IntegerType* Int1 = IntegerType::get(C, 1);
+ Constant* One = ConstantInt::get(Int1, 1, true);
+
+ // Conditional BranchInst
+ BranchInst* b1 = BranchInst::Create(bb0, bb1, One);
+
+ // check num operands
+ EXPECT_EQ(b1->getNumOperands(), 3U);
+
+ User::const_op_iterator b(b1->op_begin());
+
+ // check COND
+ EXPECT_NE(b, b1->op_end());
+ EXPECT_EQ(*b, One);
+ EXPECT_EQ(b1->getOperand(0), One);
+ ++b;
+
+ // check ELSE
+ EXPECT_EQ(*b, bb1);
+ EXPECT_EQ(b1->getOperand(1), bb1);
+ ++b;
+
+ // check THEN
+ EXPECT_EQ(*b, bb0);
+ EXPECT_EQ(b1->getOperand(2), bb0);
+ ++b;
+
+ EXPECT_EQ(b, b1->op_end());
+
+ // shrink it
+ b1->setUnconditionalDest(bb1);
+
+ // check num operands
+ EXPECT_EQ(b1->getNumOperands(), 1U);
+
+ User::const_op_iterator c(b1->op_begin());
+ EXPECT_NE(c, b1->op_end());
+
+ // check THEN
+ EXPECT_EQ(*c, bb1);
+ EXPECT_EQ(b1->getOperand(0), bb1);
+ ++c;
+
+ EXPECT_EQ(c, b1->op_end());
+
+ // clean up
+ delete b0;
+ delete b1;
+
+ delete bb0;
+ delete bb1;
+}
+
} // end anonymous namespace
} // end namespace llvm