1 //===- llvm/unittest/VMCore/InstructionsTest.cpp - Instructions unit tests ===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Instructions.h"
11 #include "llvm/BasicBlock.h"
12 #include "llvm/DerivedTypes.h"
13 #include "llvm/LLVMContext.h"
14 #include "gtest/gtest.h"
19 TEST(InstructionsTest, ReturnInst) {
20 LLVMContext &C(getGlobalContext());
23 const ReturnInst* r0 = ReturnInst::Create(C);
24 EXPECT_EQ(r0->getNumOperands(), 0U);
25 EXPECT_EQ(r0->op_begin(), r0->op_end());
27 const IntegerType* Int1 = IntegerType::get(C, 1);
28 Constant* One = ConstantInt::get(Int1, 1, true);
29 const ReturnInst* r1 = ReturnInst::Create(C, One);
30 EXPECT_EQ(r1->getNumOperands(), 1U);
31 User::const_op_iterator b(r1->op_begin());
32 EXPECT_NE(b, r1->op_end());
34 EXPECT_EQ(r1->getOperand(0), One);
36 EXPECT_EQ(b, r1->op_end());
43 TEST(InstructionsTest, BranchInst) {
44 LLVMContext &C(getGlobalContext());
47 BasicBlock* bb0 = BasicBlock::Create(C);
48 BasicBlock* bb1 = BasicBlock::Create(C);
50 // Mandatory BranchInst
51 const BranchInst* b0 = BranchInst::Create(bb0);
54 EXPECT_EQ(b0->getNumOperands(), 1U);
56 EXPECT_NE(b0->op_begin(), b0->op_end());
58 const IntegerType* Int1 = IntegerType::get(C, 1);
59 Constant* One = ConstantInt::get(Int1, 1, true);
61 // Conditional BranchInst
62 BranchInst* b1 = BranchInst::Create(bb0, bb1, One);
65 EXPECT_EQ(b1->getNumOperands(), 3U);
67 User::const_op_iterator b(b1->op_begin());
70 EXPECT_NE(b, b1->op_end());
72 EXPECT_EQ(b1->getOperand(0), One);
77 EXPECT_EQ(b1->getOperand(1), bb1);
82 EXPECT_EQ(b1->getOperand(2), bb0);
85 EXPECT_EQ(b, b1->op_end());
88 b1->setUnconditionalDest(bb1);
91 EXPECT_EQ(b1->getNumOperands(), 1U);
93 User::const_op_iterator c(b1->op_begin());
94 EXPECT_NE(c, b1->op_end());
98 EXPECT_EQ(b1->getOperand(0), bb1);
101 EXPECT_EQ(c, b1->op_end());
111 } // end anonymous namespace
112 } // end namespace llvm