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/Analysis/Verifier.h"
16 #include "gtest/gtest.h"
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
);
29 // To avoid triggering an assertion in BranchInst::Create, we first create
30 // a branch with an 'i1' condition ...
32 Constant
*False
= ConstantInt::getFalse(C
);
33 BranchInst
*BI
= BranchInst::Create(Exit
, Exit
, False
, Entry
);
35 // ... then use setOperand to redirect it to a value of different type.
37 Constant
*Zero32
= ConstantInt::get(IntegerType::get(C
, 32), 0);
38 BI
->setOperand(0, Zero32
);
40 EXPECT_TRUE(verifyFunction(*F
, ReturnStatusAction
));