Add assert to check if the attributes ZExt/SExt, NoAlias are apply to the
authorZhou Sheng <zhousheng00@gmail.com>
Thu, 7 Jun 2007 06:12:03 +0000 (06:12 +0000)
committerZhou Sheng <zhousheng00@gmail.com>
Thu, 7 Jun 2007 06:12:03 +0000 (06:12 +0000)
correct type of parameters.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37486 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Verifier.cpp

index 7e92eb303d781d42f6e2d63a56ce077f55c610d4..ef7b3f8dbbced477a30c7ae831ce5c03565366a8 100644 (file)
@@ -46,6 +46,7 @@
 #include "llvm/Pass.h"
 #include "llvm/Module.h"
 #include "llvm/ModuleProvider.h"
+#include "llvm/ParameterAttributes.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/InlineAsm.h"
 #include "llvm/Instructions.h"
@@ -358,6 +359,20 @@ void Verifier::visitFunction(Function &F) {
            FT->getNumParams() > 0 && isa<PointerType>(FT->getParamType(0))),
           "Invalid struct-return function!", &F);
 
+  if (const ParamAttrsList *Attrs = FT->getParamAttrs()) {
+    unsigned Idx = 1;
+    for (FunctionType::param_iterator I = FT->param_begin(), 
+         E = FT->param_end(); I != E; ++I, ++Idx) {
+      if (Attrs->paramHasAttr(Idx, ParamAttr::ZExt) ||
+          Attrs->paramHasAttr(Idx, ParamAttr::SExt))
+        Assert1(FT->getParamType(Idx-1)->isInteger(),
+                "Attribute ZExt should only apply to Integer type!", &F);
+      if (Attrs->paramHasAttr(Idx, ParamAttr::NoAlias))
+        Assert1(isa<PointerType>(FT->getParamType(Idx-1)),
+                "Attribute NoAlias should only apply to Pointer type!", &F);
+    }
+  }
+
   // Check that this function meets the restrictions on this calling convention.
   switch (F.getCallingConv()) {
   default: