[llvm] r269182 - Delete duplicated verifier test.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed May 11 06:23:53 PDT 2016


Author: rafael
Date: Wed May 11 08:23:52 2016
New Revision: 269182

URL: http://llvm.org/viewvc/llvm-project?rev=269182&view=rev
Log:
Delete duplicated verifier test.

Also add unittest to show we still detect the errors.

Modified:
    llvm/trunk/lib/IR/Verifier.cpp
    llvm/trunk/unittests/IR/VerifierTest.cpp

Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=269182&r1=269181&r2=269182&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Wed May 11 08:23:52 2016
@@ -557,9 +557,6 @@ void Verifier::visitGlobalVariable(const
              &GV);
       Assert(!GV.hasComdat(), "'common' global may not be in a Comdat!", &GV);
     }
-  } else {
-    Assert(GV.hasExternalLinkage() || GV.hasExternalWeakLinkage(),
-           "invalid linkage type for global declaration", &GV);
   }
 
   if (GV.hasName() && (GV.getName() == "llvm.global_ctors" ||
@@ -1963,8 +1960,6 @@ void Verifier::visitFunction(const Funct
     Assert(MDs.empty(), "unmaterialized function cannot have metadata", &F,
            MDs.empty() ? nullptr : MDs.front().second);
   } else if (F.isDeclaration()) {
-    Assert(F.hasExternalLinkage() || F.hasExternalWeakLinkage(),
-           "invalid linkage type for function declaration", &F);
     Assert(MDs.empty(), "function without a body cannot have metadata", &F,
            MDs.empty() ? nullptr : MDs.front().second);
     Assert(!F.hasPersonalityFn(),

Modified: llvm/trunk/unittests/IR/VerifierTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/VerifierTest.cpp?rev=269182&r1=269181&r2=269182&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/VerifierTest.cpp (original)
+++ llvm/trunk/unittests/IR/VerifierTest.cpp Wed May 11 08:23:52 2016
@@ -145,6 +145,33 @@ TEST(VerifierTest, CrossModuleMetadataRe
                   .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) {




More information about the llvm-commits mailing list