Mercurial > hg > CbC > CbC_llvm
comparison unittests/IR/VerifierTest.cpp @ 148:63bd29f05246
merged
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 14 Aug 2019 19:46:37 +0900 |
parents | c2174574ed3a |
children |
comparison
equal
deleted
inserted
replaced
146:3fc4d5c3e21e | 148:63bd29f05246 |
---|---|
1 //===- llvm/unittest/IR/VerifierTest.cpp - Verifier unit tests --*- C++ -*-===// | 1 //===- llvm/unittest/IR/VerifierTest.cpp - Verifier unit tests --*- C++ -*-===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 // | 4 // See https://llvm.org/LICENSE.txt for license information. |
5 // This file is distributed under the University of Illinois Open Source | 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 // License. See LICENSE.TXT for details. | |
7 // | 6 // |
8 //===----------------------------------------------------------------------===// | 7 //===----------------------------------------------------------------------===// |
9 | 8 |
10 #include "llvm/IR/Verifier.h" | 9 #include "llvm/IR/Verifier.h" |
11 #include "llvm/IR/Constants.h" | 10 #include "llvm/IR/Constants.h" |
25 | 24 |
26 TEST(VerifierTest, Branch_i1) { | 25 TEST(VerifierTest, Branch_i1) { |
27 LLVMContext C; | 26 LLVMContext C; |
28 Module M("M", C); | 27 Module M("M", C); |
29 FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg=*/false); | 28 FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg=*/false); |
30 Function *F = cast<Function>(M.getOrInsertFunction("foo", FTy)); | 29 Function *F = Function::Create(FTy, Function::ExternalLinkage, "foo", M); |
31 BasicBlock *Entry = BasicBlock::Create(C, "entry", F); | 30 BasicBlock *Entry = BasicBlock::Create(C, "entry", F); |
32 BasicBlock *Exit = BasicBlock::Create(C, "exit", F); | 31 BasicBlock *Exit = BasicBlock::Create(C, "exit", F); |
33 ReturnInst::Create(C, Exit); | 32 ReturnInst::Create(C, Exit); |
34 | 33 |
35 // To avoid triggering an assertion in BranchInst::Create, we first create | 34 // To avoid triggering an assertion in BranchInst::Create, we first create |
48 | 47 |
49 TEST(VerifierTest, InvalidRetAttribute) { | 48 TEST(VerifierTest, InvalidRetAttribute) { |
50 LLVMContext C; | 49 LLVMContext C; |
51 Module M("M", C); | 50 Module M("M", C); |
52 FunctionType *FTy = FunctionType::get(Type::getInt32Ty(C), /*isVarArg=*/false); | 51 FunctionType *FTy = FunctionType::get(Type::getInt32Ty(C), /*isVarArg=*/false); |
53 Function *F = cast<Function>(M.getOrInsertFunction("foo", FTy)); | 52 Function *F = Function::Create(FTy, Function::ExternalLinkage, "foo", M); |
54 AttributeList AS = F->getAttributes(); | 53 AttributeList AS = F->getAttributes(); |
55 F->setAttributes( | 54 F->setAttributes( |
56 AS.addAttribute(C, AttributeList::ReturnIndex, Attribute::UWTable)); | 55 AS.addAttribute(C, AttributeList::ReturnIndex, Attribute::UWTable)); |
57 | 56 |
58 std::string Error; | 57 std::string Error; |
66 LLVMContext C; | 65 LLVMContext C; |
67 Module M1("M1", C); | 66 Module M1("M1", C); |
68 Module M2("M2", C); | 67 Module M2("M2", C); |
69 Module M3("M3", C); | 68 Module M3("M3", C); |
70 FunctionType *FTy = FunctionType::get(Type::getInt32Ty(C), /*isVarArg=*/false); | 69 FunctionType *FTy = FunctionType::get(Type::getInt32Ty(C), /*isVarArg=*/false); |
71 Function *F1 = cast<Function>(M1.getOrInsertFunction("foo1", FTy)); | 70 Function *F1 = Function::Create(FTy, Function::ExternalLinkage, "foo1", M1); |
72 Function *F2 = cast<Function>(M2.getOrInsertFunction("foo2", FTy)); | 71 Function *F2 = Function::Create(FTy, Function::ExternalLinkage, "foo2", M2); |
73 Function *F3 = cast<Function>(M3.getOrInsertFunction("foo3", FTy)); | 72 Function *F3 = Function::Create(FTy, Function::ExternalLinkage, "foo3", M3); |
74 | 73 |
75 BasicBlock *Entry1 = BasicBlock::Create(C, "entry", F1); | 74 BasicBlock *Entry1 = BasicBlock::Create(C, "entry", F1); |
76 BasicBlock *Entry3 = BasicBlock::Create(C, "entry", F3); | 75 BasicBlock *Entry3 = BasicBlock::Create(C, "entry", F3); |
77 | 76 |
78 // BAD: Referencing function in another module | 77 // BAD: Referencing function in another module |
172 DIB.createFile("broken.c", "/"), | 171 DIB.createFile("broken.c", "/"), |
173 "unittest", false, "", 0); | 172 "unittest", false, "", 0); |
174 new GlobalVariable(M, Type::getInt8Ty(C), false, | 173 new GlobalVariable(M, Type::getInt8Ty(C), false, |
175 GlobalValue::ExternalLinkage, nullptr, "g"); | 174 GlobalValue::ExternalLinkage, nullptr, "g"); |
176 | 175 |
177 auto *F = cast<Function>(M.getOrInsertFunction( | 176 auto *F = Function::Create(FunctionType::get(Type::getVoidTy(C), false), |
178 "f", FunctionType::get(Type::getVoidTy(C), false))); | 177 Function::ExternalLinkage, "f", M); |
179 IRBuilder<> Builder(BasicBlock::Create(C, "", F)); | 178 IRBuilder<> Builder(BasicBlock::Create(C, "", F)); |
180 Builder.CreateUnreachable(); | 179 Builder.CreateUnreachable(); |
181 F->setSubprogram(DIB.createFunction(CU, "f", "f", | 180 F->setSubprogram(DIB.createFunction( |
182 DIB.createFile("broken.c", "/"), 1, | 181 CU, "f", "f", DIB.createFile("broken.c", "/"), 1, nullptr, 1, |
183 nullptr, true, true, 1)); | 182 DINode::FlagZero, |
183 DISubprogram::SPFlagLocalToUnit | DISubprogram::SPFlagDefinition)); | |
184 DIB.finalize(); | 184 DIB.finalize(); |
185 EXPECT_FALSE(verifyModule(M)); | 185 EXPECT_FALSE(verifyModule(M)); |
186 | 186 |
187 // Now break it by not listing the CU at all. | 187 // Now break it by not listing the CU at all. |
188 M.eraseNamedMetadata(M.getOrInsertNamedMetadata("llvm.dbg.cu")); | 188 M.eraseNamedMetadata(M.getOrInsertNamedMetadata("llvm.dbg.cu")); |