diff options
Diffstat (limited to 'llvm/unittests/IR/VerifierTest.cpp')
-rw-r--r-- | llvm/unittests/IR/VerifierTest.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/llvm/unittests/IR/VerifierTest.cpp b/llvm/unittests/IR/VerifierTest.cpp index 8f2838279d1..85148afdeca 100644 --- a/llvm/unittests/IR/VerifierTest.cpp +++ b/llvm/unittests/IR/VerifierTest.cpp @@ -145,6 +145,33 @@ TEST(VerifierTest, CrossModuleMetadataRef) { .startswith("Referencing global in another module!")); } +TEST(VerifierTest, InvalidVariableLinkage) { + LLVMContext C; + Module M("M", C); + new GlobalVariable(M, Type::getInt8Ty(C), false, + GlobalValue::LinkOnceODRLinkage, nullptr, "Some Global"); + std::string Error; + raw_string_ostream ErrorOS(Error); + EXPECT_TRUE(verifyModule(M, &ErrorOS)); + EXPECT_TRUE( + StringRef(ErrorOS.str()).startswith("Global is external, but doesn't " + "have external or weak linkage!")); +} + +TEST(VerifierTest, InvalidFunctionLinkage) { + LLVMContext C; + Module M("M", C); + + FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg=*/false); + Function::Create(FTy, GlobalValue::LinkOnceODRLinkage, "foo", &M); + std::string Error; + raw_string_ostream ErrorOS(Error); + EXPECT_TRUE(verifyModule(M, &ErrorOS)); + EXPECT_TRUE( + StringRef(ErrorOS.str()).startswith("Global is external, but doesn't " + "have external or weak linkage!")); +} + #ifndef _MSC_VER // FIXME: This test causes an ICE in MSVC 2013. TEST(VerifierTest, StripInvalidDebugInfo) { |