- Add a "getOrInsertGlobal" method to the Module class. This acts similarly to
[oota-llvm.git] / lib / VMCore / Verifier.cpp
index c7808681d88e272f337234931c21df7474de3dbb..f8dd24c3af62f0f7eea74b92fc96742eff954ed5 100644 (file)
@@ -415,12 +415,11 @@ void Verifier::VerifyAttrs(Attributes Attrs, const Type *Ty,
     Attributes RetI = Attrs & Attribute::ParameterOnly;
     Assert1(!RetI, "Attribute " + Attribute::getAsString(RetI) +
             " does not apply to return values!", V);
-  } else {
-    Attributes ParmI = Attrs & Attribute::ReturnOnly;
-    Assert1(!ParmI, "Attribute " + Attribute::getAsString(ParmI) +
-            " only applies to return values!", V);
   }
-
+  Attributes FnCheckAttr = Attrs & Attribute::FunctionOnly;
+  Assert1(!FnCheckAttr, "Attribute " + Attribute::getAsString(FnCheckAttr) +
+          " only applies to functions!", V);
+  
   for (unsigned i = 0;
        i < array_lengthof(Attribute::MutuallyIncompatible); ++i) {
     Attributes MutI = Attrs & Attribute::MutuallyIncompatible[i];
@@ -475,6 +474,18 @@ void Verifier::VerifyFunctionAttrs(const FunctionType *FT,
     if (Attr.Attrs & Attribute::StructRet)
       Assert1(Attr.Index == 1, "Attribute sret not on first parameter!", V);
   }
+
+  Attributes FAttrs = Attrs.getFnAttributes();
+  Assert1(!(FAttrs & (~Attribute::FunctionOnly)),
+          "Attribute " + Attribute::getAsString(FAttrs) +
+          " does not apply to function!", V);
+      
+  for (unsigned i = 0;
+       i < array_lengthof(Attribute::MutuallyIncompatible); ++i) {
+    Attributes MutI = FAttrs & Attribute::MutuallyIncompatible[i];
+    Assert1(!(MutI & (MutI - 1)), "Attributes " +
+            Attribute::getAsString(MutI) + " are incompatible!", V);
+  }
 }
 
 static bool VerifyAttributeCount(const AttrListPtr &Attrs, unsigned Params) {
@@ -521,7 +532,6 @@ void Verifier::visitFunction(Function &F) {
   default:
     break;
   case CallingConv::C:
-  case CallingConv::X86_SSECall:
     break;
   case CallingConv::Fast:
   case CallingConv::Cold:
@@ -976,7 +986,7 @@ void Verifier::VerifyCallSite(CallSite CS) {
   if (FTy->isVarArg())
     // Check attributes on the varargs part.
     for (unsigned Idx = 1 + FTy->getNumParams(); Idx <= CS.arg_size(); ++Idx) {
-      Attributes Attr = Attrs.getAttributes(Idx);
+      Attributes Attr = Attrs.getParamAttributes(Idx);
 
       VerifyAttrs(Attr, CS.getArgument(Idx-1)->getType(), false, I);
 
@@ -1337,8 +1347,10 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
   case Intrinsic::gcwrite:
   case Intrinsic::gcread:
     if (ID == Intrinsic::gcroot) {
-      Assert1(isa<AllocaInst>(CI.getOperand(1)->stripPointerCasts()),
-              "llvm.gcroot parameter #1 must be an alloca.", &CI);
+      AllocaInst *AI =
+        dyn_cast<AllocaInst>(CI.getOperand(1)->stripPointerCasts());
+      Assert1(AI && isa<PointerType>(AI->getType()->getElementType()),
+              "llvm.gcroot parameter #1 must be a pointer alloca.", &CI);
       Assert1(isa<Constant>(CI.getOperand(2)),
               "llvm.gcroot parameter #2 must be a constant.", &CI);
     }
@@ -1351,6 +1363,14 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
             "llvm.init_trampoline parameter #2 must resolve to a function.",
             &CI);
     break;
+  case Intrinsic::prefetch:
+    Assert1(isa<ConstantInt>(CI.getOperand(2)) &&
+            isa<ConstantInt>(CI.getOperand(3)) &&
+            cast<ConstantInt>(CI.getOperand(2))->getZExtValue() < 2 &&
+            cast<ConstantInt>(CI.getOperand(3))->getZExtValue() < 4,
+            "invalid arguments to llvm.prefetch",
+            &CI);
+    break;
   }
 }