Add an empty key for DebugLoc so that you can store an empty DebugLoc in a
[llvm/stm8.git] / unittests / VMCore / VerifierTest.cpp
blob1924661200b5370735f193aa654f6b4c5c82a976
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 //===----------------------------------------------------------------------===//
10 #include "llvm/Constants.h"
11 #include "llvm/DerivedTypes.h"
12 #include "llvm/Function.h"
13 #include "llvm/GlobalAlias.h"
14 #include "llvm/GlobalVariable.h"
15 #include "llvm/Instructions.h"
16 #include "llvm/LLVMContext.h"
17 #include "llvm/Module.h"
18 #include "llvm/ADT/OwningPtr.h"
19 #include "llvm/Analysis/Verifier.h"
20 #include "gtest/gtest.h"
22 namespace llvm {
23 namespace {
25 TEST(VerifierTest, Branch_i1) {
26 LLVMContext &C = getGlobalContext();
27 FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg=*/false);
28 OwningPtr<Function> F(Function::Create(FTy, GlobalValue::ExternalLinkage));
29 BasicBlock *Entry = BasicBlock::Create(C, "entry", F.get());
30 BasicBlock *Exit = BasicBlock::Create(C, "exit", F.get());
31 ReturnInst::Create(C, Exit);
33 // To avoid triggering an assertion in BranchInst::Create, we first create
34 // a branch with an 'i1' condition ...
36 Constant *False = ConstantInt::getFalse(C);
37 BranchInst *BI = BranchInst::Create(Exit, Exit, False, Entry);
39 // ... then use setOperand to redirect it to a value of different type.
41 Constant *Zero32 = ConstantInt::get(IntegerType::get(C, 32), 0);
42 BI->setOperand(0, Zero32);
44 EXPECT_TRUE(verifyFunction(*F, ReturnStatusAction));
47 TEST(VerifierTest, AliasUnnamedAddr) {
48 LLVMContext &C = getGlobalContext();
49 Module M("M", C);
50 const Type *Ty = Type::getInt8Ty(C);
51 Constant *Init = Constant::getNullValue(Ty);
52 GlobalVariable *Aliasee = new GlobalVariable(M, Ty, true,
53 GlobalValue::ExternalLinkage,
54 Init, "foo");
55 GlobalAlias *GA = new GlobalAlias(Type::getInt8PtrTy(C),
56 GlobalValue::ExternalLinkage,
57 "bar", Aliasee, &M);
58 GA->setUnnamedAddr(true);
59 std::string Error;
60 EXPECT_TRUE(verifyModule(M, ReturnStatusAction, &Error));
61 EXPECT_TRUE(StringRef(Error).startswith("Alias cannot have unnamed_addr"));