Change the verifier to never throw an exception. Instead verifyModule canoptionally...
authorChris Lattner <sabre@nondot.org>
Thu, 6 Jul 2006 18:02:27 +0000 (18:02 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 6 Jul 2006 18:02:27 +0000 (18:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29017 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Bytecode/Reader/Analyzer.cpp
lib/VMCore/Verifier.cpp
tools/llvm-as/llvm-as.cpp
tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
tools/llvm2cpp/llvm2cpp.cpp

index 0152104acb8990fdeb5e1f3441ac9555d72d790f..ce20ac2e3a52fe96e02ece0785d5fad7f23f4de1 100644 (file)
@@ -117,12 +117,10 @@ public:
     bca.functionDensity = double(bca.BlockSizes[BytecodeFormat::FunctionBlockID]) /
       double(bca.numFunctions);
 
-    if ( bca.progressiveVerify ) {
-      try {
-        verifyModule(*M, ThrowExceptionAction);
-      } catch ( std::string& msg ) {
+    if (bca.progressiveVerify) {
+      std::string msg;
+      if (verifyModule(*M, ReturnStatusAction, &msg))
         bca.VerifyInfo += "Verify@Finish: " + msg + "\n";
-      }
     }
   }
 
@@ -135,12 +133,10 @@ public:
   virtual void handleModuleEnd(const std::string& id) {
     if (os)
       *os << "  } End Module " << id << "\n";
-    if ( bca.progressiveVerify ) {
-      try {
-        verifyModule(*M, ThrowExceptionAction);
-      } catch ( std::string& msg ) {
+    if (bca.progressiveVerify) {
+      std::string msg;
+      if (verifyModule(*M, ReturnStatusAction, &msg))
         bca.VerifyInfo += "Verify@EndModule: " + msg + "\n";
-      }
     }
   }
 
@@ -232,12 +228,10 @@ public:
   virtual void handleModuleGlobalsEnd() {
     if (os)
       *os << "    } END BLOCK: ModuleGlobalInfo\n";
-    if ( bca.progressiveVerify ) {
-      try {
-        verifyModule(*M, ThrowExceptionAction);
-      } catch ( std::string& msg ) {
+    if (bca.progressiveVerify) {
+      std::string msg;
+      if (verifyModule(*M, ReturnStatusAction, &msg))
         bca.VerifyInfo += "Verify@EndModuleGlobalInfo: " + msg + "\n";
-      }
     }
   }
 
@@ -346,12 +340,10 @@ public:
     currFunc->density = double(currFunc->byteSize) /
       double(currFunc->numInstructions);
 
-    if ( bca.progressiveVerify ) {
-      try {
-        verifyModule(*M, ThrowExceptionAction);
-      } catch ( std::string& msg ) {
+    if (bca.progressiveVerify) {
+      std::string msg;
+      if (verifyModule(*M, ReturnStatusAction, &msg))
         bca.VerifyInfo += "Verify@EndFunction: " + msg + "\n";
-      }
     }
   }
 
@@ -522,12 +514,10 @@ public:
     if (os)
       *os << "    } END BLOCK: GlobalConstants\n";
 
-    if ( bca.progressiveVerify ) {
-      try {
-        verifyModule(*M, ThrowExceptionAction);
-      } catch ( std::string& msg ) {
+    if (bca.progressiveVerify) {
+      std::string msg;
+      if (verifyModule(*M, ReturnStatusAction, &msg))
         bca.VerifyInfo += "Verify@EndGlobalConstants: " + msg + "\n";
-      }
     }
   }
 
index d07345e932997d5d6394b14fa37ddd4731e079f6..9379abcfd1801c0f103f8771585ca9975d37e519 100644 (file)
@@ -152,18 +152,13 @@ namespace {  // Anonymous namespace for class
     /// this condition, do so.
     ///
     void abortIfBroken() {
-      if (Broken)
-      {
+      if (Broken) {
         msgs << "Broken module found, ";
-        switch (action)
-        {
+        switch (action) {
           case AbortProcessAction:
             msgs << "compilation aborted!\n";
             std::cerr << msgs.str();
             abort();
-          case ThrowExceptionAction:
-            msgs << "verification terminated.\n";
-            throw msgs.str();
           case PrintMessageAction:
             msgs << "verification continues.\n";
             std::cerr << msgs.str();
@@ -799,11 +794,15 @@ bool llvm::verifyFunction(const Function &f, VerifierFailureAction action) {
 /// verifyModule - Check a module for errors, printing messages on stderr.
 /// Return true if the module is corrupt.
 ///
-bool llvm::verifyModule(const Module &M, VerifierFailureAction action) {
+bool llvm::verifyModule(const Module &M, VerifierFailureAction action,
+                        std::string *ErrorInfo) {
   PassManager PM;
   Verifier *V = new Verifier(action);
   PM.add(V);
   PM.run((Module&)M);
+  
+  if (ErrorInfo && V->Broken)
+    *ErrorInfo = V->msgs.str();
   return V->Broken;
 }
 
index 1dbcd1d1b839a5eddaea71479278b44b599070ec..9547ad13e258f5ce09d04e8d0cb00c7c41571393 100644 (file)
@@ -63,14 +63,14 @@ int main(int argc, char **argv) {
       return 1;
     }
 
-    try {
-      if (!DisableVerify)
-        verifyModule(*M.get(), ThrowExceptionAction);
-    } catch (const std::string &Err) {
-      std::cerr << argv[0]
-                << ": assembly parsed, but does not verify as correct!\n";
-      std::cerr << Err;
-      return 1;
+    if (!DisableVerify) {
+      std::string Err;
+      if (verifyModule(*M.get(), ReturnStatusAction, &Err)) {
+        std::cerr << argv[0]
+                  << ": assembly parsed, but does not verify as correct!\n";
+        std::cerr << Err;
+        return 1;
+      } 
     }
 
     if (DumpAsm) std::cerr << "Here's the assembly:\n" << *M.get();
index 39131cfb3c498d718d1b29d735327378877694d9..2ac78344c69bbd05a0b2bcdfbc2210c37e5cc9f3 100644 (file)
@@ -73,23 +73,10 @@ main(int argc, char **argv) {
 
     if ( M && Verify ) {
       std::string verificationMsg;
-      try {
-        verifyModule( *M, ThrowExceptionAction );
-      } catch (std::string& errmsg ) {
-        verificationMsg = errmsg;
-      }
-      if ( verificationMsg.length() > 0 )
+      if (verifyModule(*M, ReturnStatusAction, &verificationMsg))
         std::cerr << "Final Verification Message: " << verificationMsg << "\n";
     }
 
-
-    // If there was an error, print it and stop.
-    if ( ErrorMessage.size() ) {
-      std::cerr << argv[0] << ": " << ErrorMessage << "\n";
-      return 1;
-    }
-
-
     if (Out != &std::cout) {
       ((std::ofstream*)Out)->close();
       delete Out;
index 9035e71c075da09fb604e67de72c83b4438dcd5f..7e322dbef8162262ada9ea7061c7aa7d7a789d3b 100644 (file)
@@ -59,14 +59,16 @@ int main(int argc, char **argv) {
       return 1;
     }
 
-    try {
-      if (!DisableVerify)
-        verifyModule(*M.get(), ThrowExceptionAction);
-    } catch (const std::string &Err) {
-      std::cerr << argv[0]
-                << ": assembly parsed, but does not verify as correct!\n";
-      std::cerr << Err;
-      return 1;
+    // FIXME: llvm2cpp should read .bc files and thus not run the verifier
+    // explicitly!
+    if (!DisableVerify) {
+      std::string Err;
+      if (verifyModule(*M.get(), ReturnStatusAction, &Err)) {
+        std::cerr << argv[0]
+                  << ": assembly parsed, but does not verify as correct!\n";
+        std::cerr << Err;
+        return 1;
+      } 
     }
 
     if (OutputFilename != "") {   // Specified an output filename?