[llvm-commits] [llvm] r45909 - in /llvm/trunk: include/llvm/ParameterAttributes.h lib/VMCore/Verifier.cpp test/Verifier/2008-01-11-VarargAttrs.ll

Duncan Sands baldrick at free.fr
Sat Jan 12 08:42:02 PST 2008


Author: baldrick
Date: Sat Jan 12 10:42:01 2008
New Revision: 45909

URL: http://llvm.org/viewvc/llvm-project?rev=45909&view=rev
Log:
Be more liberal in what parameter attributes are
allowed on the vararg arguments of a call.

Modified:
    llvm/trunk/include/llvm/ParameterAttributes.h
    llvm/trunk/lib/VMCore/Verifier.cpp
    llvm/trunk/test/Verifier/2008-01-11-VarargAttrs.ll

Modified: llvm/trunk/include/llvm/ParameterAttributes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ParameterAttributes.h?rev=45909&r1=45908&r2=45909&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ParameterAttributes.h (original)
+++ llvm/trunk/include/llvm/ParameterAttributes.h Sat Jan 12 10:42:01 2008
@@ -52,8 +52,8 @@
 /// @brief Attributes that only apply to function return values.
 const uint16_t ReturnOnly = NoReturn | NoUnwind | ReadNone | ReadOnly;
 
-/// @brief Attributes that can apply to vararg call arguments.
-const uint16_t VarArgsCompatible = ByVal;
+/// @brief Parameter attributes that do not apply to vararg call arguments.
+const uint16_t VarArgsIncompatible = Nest | StructRet;
 
 /// @brief Attributes that are mutually incompatible.
 const uint16_t MutuallyIncompatible[3] = {

Modified: llvm/trunk/lib/VMCore/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Verifier.cpp?rev=45909&r1=45908&r2=45909&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Verifier.cpp (original)
+++ llvm/trunk/lib/VMCore/Verifier.cpp Sat Jan 12 10:42:01 2008
@@ -261,8 +261,10 @@
     void VerifyCallSite(CallSite CS);
     void VerifyIntrinsicPrototype(Intrinsic::ID ID, Function *F,
                                   unsigned Count, ...);
-    void VerifyParamAttrs(const FunctionType *FT, const ParamAttrsList *Attrs,
-                          const Value *V);
+    void VerifyAttrs(uint16_t Attrs, const Type *Ty, bool isReturnValue,
+                     const Value *V);
+    void VerifyFunctionAttrs(const FunctionType *FT, const ParamAttrsList *Attrs,
+                             const Value *V);
 
     void WriteValue(const Value *V) {
       if (!V) return;
@@ -382,11 +384,40 @@
 void Verifier::verifyTypeSymbolTable(TypeSymbolTable &ST) {
 }
 
-// VerifyParamAttrs - Check parameter attributes against a function type.
+// VerifyAttrs - Check the given parameter attributes for an argument or return
+// value of the specified type.  The value V is printed in error messages.
+void Verifier::VerifyAttrs(uint16_t Attrs, const Type *Ty, bool isReturnValue,
+                           const Value *V) {
+  if (Attrs == ParamAttr::None)
+    return;
+
+  if (isReturnValue) {
+    uint16_t RetI = Attrs & ParamAttr::ParameterOnly;
+    Assert1(!RetI, "Attribute " + ParamAttrsList::getParamAttrsText(RetI) +
+            "does not apply to return values!", V);
+  } else {
+    uint16_t ParmI = Attrs & ParamAttr::ReturnOnly;
+    Assert1(!ParmI, "Attribute " + ParamAttrsList::getParamAttrsText(ParmI) +
+            "only applies to return values!", V);
+  }
+
+  for (unsigned i = 0;
+       i < array_lengthof(ParamAttr::MutuallyIncompatible); ++i) {
+    uint16_t MutI = Attrs & ParamAttr::MutuallyIncompatible[i];
+    Assert1(!(MutI & (MutI - 1)), "Attributes " +
+            ParamAttrsList::getParamAttrsText(MutI) + "are incompatible!", V);
+  }
+
+  uint16_t TypeI = Attrs & ParamAttr::typeIncompatible(Ty);
+  Assert1(!TypeI, "Wrong type for attribute " +
+          ParamAttrsList::getParamAttrsText(TypeI), V);
+}
+
+// VerifyFunctionAttrs - Check parameter attributes against a function type.
 // The value V is printed in error messages.
-void Verifier::VerifyParamAttrs(const FunctionType *FT,
-                                const ParamAttrsList *Attrs,
-                                const Value *V) {
+void Verifier::VerifyFunctionAttrs(const FunctionType *FT,
+                                   const ParamAttrsList *Attrs,
+                                   const Value *V) {
   if (!Attrs)
     return;
 
@@ -395,27 +426,7 @@
   for (unsigned Idx = 0; Idx <= FT->getNumParams(); ++Idx) {
     uint16_t Attr = Attrs->getParamAttrs(Idx);
 
-    if (!Idx) {
-      uint16_t RetI = Attr & ParamAttr::ParameterOnly;
-      Assert1(!RetI, "Attribute " + Attrs->getParamAttrsText(RetI) +
-              "does not apply to return values!", V);
-    } else {
-      uint16_t ParmI = Attr & ParamAttr::ReturnOnly;
-      Assert1(!ParmI, "Attribute " + Attrs->getParamAttrsText(ParmI) +
-              "only applies to return values!", V);
-    }
-
-    for (unsigned i = 0;
-         i < array_lengthof(ParamAttr::MutuallyIncompatible); ++i) {
-      uint16_t MutI = Attr & ParamAttr::MutuallyIncompatible[i];
-      Assert1(!(MutI & (MutI - 1)), "Attributes " +
-              Attrs->getParamAttrsText(MutI) + "are incompatible!", V);
-    }
-
-    uint16_t TypeI =
-      Attr & ParamAttr::typeIncompatible(FT->getParamType(Idx-1));
-    Assert1(!TypeI, "Wrong type for attribute " +
-            Attrs->getParamAttrsText(TypeI), V);
+    VerifyAttrs(Attr, FT->getParamType(Idx-1), !Idx, V);
 
     if (Attr & ParamAttr::Nest) {
       Assert1(!SawNest, "More than one parameter has attribute nest!", V);
@@ -453,7 +464,7 @@
           "Attributes after last parameter!", &F);
 
   // Check function attributes.
-  VerifyParamAttrs(FT, Attrs, &F);
+  VerifyFunctionAttrs(FT, Attrs, &F);
 
   // Check that this function meets the restrictions on this calling convention.
   switch (F.getCallingConv()) {
@@ -857,14 +868,17 @@
           "Attributes after last argument!", I);
 
   // Verify call attributes.
-  VerifyParamAttrs(FTy, Attrs, I);
+  VerifyFunctionAttrs(FTy, Attrs, I);
 
   if (Attrs && FTy->isVarArg())
     // Check attributes on the varargs part.
     for (unsigned Idx = 1 + FTy->getNumParams(); Idx <= CS.arg_size(); ++Idx) {
       uint16_t Attr = Attrs->getParamAttrs(Idx);
-      uint16_t VArgI = Attr & ~ParamAttr::VarArgsCompatible;
-      Assert1(!VArgI, "Attribute " + Attrs->getParamAttrsText(VArgI) +
+
+      VerifyAttrs(Attr, CS.getArgument(Idx-1)->getType(), false, I);
+
+      uint16_t VArgI = Attr & ParamAttr::VarArgsIncompatible;
+      Assert1(!VArgI, "Attribute " + ParamAttrsList::getParamAttrsText(VArgI) +
               "cannot be used for vararg call arguments!", I);
     }
 

Modified: llvm/trunk/test/Verifier/2008-01-11-VarargAttrs.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Verifier/2008-01-11-VarargAttrs.ll?rev=45909&r1=45908&r2=45909&view=diff

==============================================================================
--- llvm/trunk/test/Verifier/2008-01-11-VarargAttrs.ll (original)
+++ llvm/trunk/test/Verifier/2008-01-11-VarargAttrs.ll Sat Jan 12 10:42:01 2008
@@ -1,10 +1,10 @@
-; RUN: not llvm-as < %s
+; RUN: not llvm-as < %s -o /dev/null
 
 	%struct = type {  }
 
 declare void @foo(...)
 
 define void @bar() {
-	call void (...)* @foo(%struct* inreg null )
+	call void (...)* @foo(%struct* sret null )
 	ret void
 }





More information about the llvm-commits mailing list