Skip to content

Commit cc8900f

Browse files
committed
Delete duplicated verifier test.
Also add unittest to show we still detect the errors. llvm-svn: 269182
1 parent 477eb42 commit cc8900f

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

llvm/lib/IR/Verifier.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,6 @@ void Verifier::visitGlobalVariable(const GlobalVariable &GV) {
557557
&GV);
558558
Assert(!GV.hasComdat(), "'common' global may not be in a Comdat!", &GV);
559559
}
560-
} else {
561-
Assert(GV.hasExternalLinkage() || GV.hasExternalWeakLinkage(),
562-
"invalid linkage type for global declaration", &GV);
563560
}
564561

565562
if (GV.hasName() && (GV.getName() == "llvm.global_ctors" ||
@@ -1963,8 +1960,6 @@ void Verifier::visitFunction(const Function &F) {
19631960
Assert(MDs.empty(), "unmaterialized function cannot have metadata", &F,
19641961
MDs.empty() ? nullptr : MDs.front().second);
19651962
} else if (F.isDeclaration()) {
1966-
Assert(F.hasExternalLinkage() || F.hasExternalWeakLinkage(),
1967-
"invalid linkage type for function declaration", &F);
19681963
Assert(MDs.empty(), "function without a body cannot have metadata", &F,
19691964
MDs.empty() ? nullptr : MDs.front().second);
19701965
Assert(!F.hasPersonalityFn(),

llvm/unittests/IR/VerifierTest.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,33 @@ TEST(VerifierTest, CrossModuleMetadataRef) {
145145
.startswith("Referencing global in another module!"));
146146
}
147147

148+
TEST(VerifierTest, InvalidVariableLinkage) {
149+
LLVMContext C;
150+
Module M("M", C);
151+
new GlobalVariable(M, Type::getInt8Ty(C), false,
152+
GlobalValue::LinkOnceODRLinkage, nullptr, "Some Global");
153+
std::string Error;
154+
raw_string_ostream ErrorOS(Error);
155+
EXPECT_TRUE(verifyModule(M, &ErrorOS));
156+
EXPECT_TRUE(
157+
StringRef(ErrorOS.str()).startswith("Global is external, but doesn't "
158+
"have external or weak linkage!"));
159+
}
160+
161+
TEST(VerifierTest, InvalidFunctionLinkage) {
162+
LLVMContext C;
163+
Module M("M", C);
164+
165+
FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg=*/false);
166+
Function::Create(FTy, GlobalValue::LinkOnceODRLinkage, "foo", &M);
167+
std::string Error;
168+
raw_string_ostream ErrorOS(Error);
169+
EXPECT_TRUE(verifyModule(M, &ErrorOS));
170+
EXPECT_TRUE(
171+
StringRef(ErrorOS.str()).startswith("Global is external, but doesn't "
172+
"have external or weak linkage!"));
173+
}
174+
148175
#ifndef _MSC_VER
149176
// FIXME: This test causes an ICE in MSVC 2013.
150177
TEST(VerifierTest, StripInvalidDebugInfo) {

0 commit comments

Comments
 (0)