Nick Lewycky | 1d9a815 | 2010-02-15 22:09:09 +0000 | [diff] [blame] | 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/Analysis/Verifier.h" |
| 16 | #include "gtest/gtest.h" |
| 17 | |
| 18 | namespace llvm { |
| 19 | namespace { |
| 20 | |
| 21 | TEST(VerifierTest, Branch_i1) { |
| 22 | LLVMContext &C = getGlobalContext(); |
| 23 | FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg=*/false); |
| 24 | Function *F = Function::Create(FTy, GlobalValue::ExternalLinkage); |
| 25 | BasicBlock *Entry = BasicBlock::Create(C, "entry", F); |
| 26 | BasicBlock *Exit = BasicBlock::Create(C, "exit", F); |
| 27 | ReturnInst::Create(C, Exit); |
| 28 | |
| 29 | // To avoid triggering an assertion in BranchInst::Create, we first create |
| 30 | // a branch with an 'i1' condition ... |
| 31 | |
| 32 | Constant *False = ConstantInt::getFalse(C); |
| 33 | BranchInst *BI = BranchInst::Create(Exit, Exit, False, Entry); |
| 34 | |
| 35 | // ... then use setOperand to redirect it to a value of different type. |
| 36 | |
| 37 | Constant *Zero32 = ConstantInt::get(IntegerType::get(C, 32), 0); |
| 38 | BI->setOperand(0, Zero32); |
| 39 | |
| 40 | EXPECT_TRUE(verifyFunction(*F, ReturnStatusAction)); |
| 41 | } |
| 42 | |
| 43 | } |
| 44 | } |