Use stripPointerCasts when checking for AllocaInsts for the stackprotector intrinsic.
[oota-llvm.git] / lib / VMCore / Verifier.cpp
index a699ab2af205292d3fc9657a5baef9d39a89eea9..ffafc77c828129088e8b445b7fd92d1aa516ee0a 100644 (file)
@@ -1374,6 +1374,11 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
             "invalid arguments to llvm.prefetch",
             &CI);
     break;
+  case Intrinsic::stackprotector:
+    Assert1(isa<AllocaInst>(CI.getOperand(2)->stripPointerCasts()),
+            "llvm.stackprotector parameter #2 must resolve to an alloca.",
+            &CI);
+    break;
   }
 }
 
@@ -1390,8 +1395,18 @@ bool Verifier::PerformTypeCheck(Intrinsic::ID ID, Function *F, const Type *Ty,
 
   if (VT < 0) {
     int Match = ~VT;
-    if (Match == 0) {
-      if (Ty != FTy->getReturnType()) {
+    const Type *RetTy = FTy->getReturnType();
+    const StructType *ST = dyn_cast<StructType>(RetTy);
+    unsigned NumRets = 1;
+
+    if (ST)
+      NumRets = ST->getNumElements();
+
+    if (Match <= static_cast<int>(NumRets - 1)) {
+      if (ST)
+        RetTy = ST->getElementType(Match);
+
+      if (Ty != RetTy) {
         CheckFailed("Intrinsic parameter #" + utostr(ArgNo - 1) + " does not "
                     "match return type.", F);
         return false;