fix off by 1 (insn) error in eh.sjlj.setjmp thumb code sequence.
[oota-llvm.git] / unittests / VMCore / VerifierTest.cpp
1 //===- llvm/unittest/VMCore/VerifierTest.cpp - Verifier unit tests --------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "llvm/Constants.h"
11 #include "llvm/DerivedTypes.h"
12 #include "llvm/Function.h"
13 #include "llvm/Instructions.h"
14 #include "llvm/LLVMContext.h"
15 #include "llvm/ADT/OwningPtr.h"
16 #include "llvm/Analysis/Verifier.h"
17 #include "gtest/gtest.h"
18
19 namespace llvm {
20 namespace {
21
22 TEST(VerifierTest, Branch_i1) {
23   LLVMContext &C = getGlobalContext();
24   FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg=*/false);
25   OwningPtr<Function> F(Function::Create(FTy, GlobalValue::ExternalLinkage));
26   BasicBlock *Entry = BasicBlock::Create(C, "entry", F.get());
27   BasicBlock *Exit = BasicBlock::Create(C, "exit", F.get());
28   ReturnInst::Create(C, Exit);
29
30   // To avoid triggering an assertion in BranchInst::Create, we first create
31   // a branch with an 'i1' condition ...
32
33   Constant *False = ConstantInt::getFalse(C);
34   BranchInst *BI = BranchInst::Create(Exit, Exit, False, Entry);
35
36   // ... then use setOperand to redirect it to a value of different type.
37
38   Constant *Zero32 = ConstantInt::get(IntegerType::get(C, 32), 0);
39   BI->setOperand(0, Zero32);
40
41   EXPECT_TRUE(verifyFunction(*F, ReturnStatusAction));
42 }
43
44 }
45 }