Adding dllimport, dllexport and external weak linkage types.
[oota-llvm.git] / lib / VMCore / Verifier.cpp
index 9379abcfd1801c0f103f8771585ca9975d37e519..cbef68b7dc35d951673edd40b66f1e18a1f59ed6 100644 (file)
@@ -57,7 +57,7 @@
 #include "llvm/Support/InstVisitor.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/Support/Visibility.h"
+#include "llvm/Support/Compiler.h"
 #include <algorithm>
 #include <iostream>
 #include <sstream>
@@ -105,7 +105,7 @@ namespace {  // Anonymous namespace for class
       // returning back to the pass manager, or else the pass manager may try to
       // run other passes on the broken module.
       if (RealPass)
-        abortIfBroken();
+        return abortIfBroken();
       return false;
     }
 
@@ -119,7 +119,7 @@ namespace {  // Anonymous namespace for class
       // returning back to the pass manager, or else the pass manager may try to
       // run other passes on the broken module.
       if (RealPass)
-        abortIfBroken();
+        return abortIfBroken();
 
       return false;
     }
@@ -138,8 +138,7 @@ namespace {  // Anonymous namespace for class
         visitGlobalVariable(*I);
 
       // If the module is broken, abort at this time.
-      abortIfBroken();
-      return false;
+      return abortIfBroken();
     }
 
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
@@ -151,7 +150,7 @@ namespace {  // Anonymous namespace for class
     /// abortIfBroken - If the module is broken and we are supposed to abort on
     /// this condition, do so.
     ///
-    void abortIfBroken() {
+    bool abortIfBroken() {
       if (Broken) {
         msgs << "Broken module found, ";
         switch (action) {
@@ -162,11 +161,13 @@ namespace {  // Anonymous namespace for class
           case PrintMessageAction:
             msgs << "verification continues.\n";
             std::cerr << msgs.str();
-            break;
+            return false;
           case ReturnStatusAction:
-            break;
+            msgs << "compilation terminated.\n";
+            return Broken;
         }
       }
+      return false;
     }
 
 
@@ -238,7 +239,7 @@ namespace {  // Anonymous namespace for class
     }
   };
 
-  RegisterOpt<Verifier> X("verify", "Module Verifier");
+  RegisterPass<Verifier> X("verify", "Module Verifier");
 } // End anonymous namespace
 
 
@@ -256,8 +257,16 @@ namespace {  // Anonymous namespace for class
 
 
 void Verifier::visitGlobalValue(GlobalValue &GV) {
-  Assert1(!GV.isExternal() || GV.hasExternalLinkage(),
-          "Global is external, but doesn't have external linkage!", &GV);
+  Assert1(!GV.isExternal() ||
+          GV.hasExternalLinkage() ||
+          GV.hasDLLImportLinkage() ||
+          GV.hasExternalWeakLinkage(),
+  "Global is external, but doesn't have external or dllimport or weak linkage!",
+          &GV);
+
+  Assert1(!GV.hasDLLImportLinkage() || GV.isExternal(),
+          "Global is marked as dllimport, but not external", &GV);
+  
   Assert1(!GV.hasAppendingLinkage() || isa<GlobalVariable>(GV),
           "Only global variables can have appending linkage!", &GV);
 
@@ -652,10 +661,16 @@ void Verifier::visitInstruction(Instruction &I) {
   }
 
   for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) {
-    // Check to make sure that the "address of" an intrinsic function is never
-    // taken.
     Assert1(I.getOperand(i) != 0, "Instruction has null operand!", &I);
+
+    // Check to make sure that only first-class-values are operands to
+    // instructions.
+    Assert1(I.getOperand(i)->getType()->isFirstClassType(),
+            "Instruction operands must be first-class values!", &I);
+  
     if (Function *F = dyn_cast<Function>(I.getOperand(i))) {
+      // Check to make sure that the "address of" an intrinsic function is never
+      // taken.
       Assert1(!F->isIntrinsic() || (i == 0 && isa<CallInst>(I)),
               "Cannot take the address of an intrinsic!", &I);
     } else if (BasicBlock *OpBB = dyn_cast<BasicBlock>(I.getOperand(i))) {