1 //===- llvm/unittest/VMCore/VerifierTest.cpp - Verifier 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/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"
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);
30 // To avoid triggering an assertion in BranchInst::Create, we first create
31 // a branch with an 'i1' condition ...
33 Constant *False = ConstantInt::getFalse(C);
34 BranchInst *BI = BranchInst::Create(Exit, Exit, False, Entry);
36 // ... then use setOperand to redirect it to a value of different type.
38 Constant *Zero32 = ConstantInt::get(IntegerType::get(C, 32), 0);
39 BI->setOperand(0, Zero32);
41 EXPECT_TRUE(verifyFunction(*F, ReturnStatusAction));