Be more liberal in what parameter attributes are
authorDuncan Sands <baldrick@free.fr>
Sat, 12 Jan 2008 16:42:01 +0000 (16:42 +0000)
committerDuncan Sands <baldrick@free.fr>
Sat, 12 Jan 2008 16:42:01 +0000 (16:42 +0000)
allowed on the vararg arguments of a call.

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

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

index 4106dcb2907ebc6d003b8b1b1db5eacfbd4691dc..ded847e146a4ebdb83d562ca427d52a197325c65 100644 (file)
@@ -52,8 +52,8 @@ const uint16_t ParameterOnly = ByVal | InReg | Nest | StructRet;
 /// @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] = {
index e42109e0f30abf82e708d8fff33aa3d3cc9ad7f6..626119b43728f0991e2940d166d25d4de19136f9 100644 (file)
@@ -261,8 +261,10 @@ namespace {  // Anonymous namespace for class
     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::visitGlobalAlias(GlobalAlias &GA) {
 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 @@ void Verifier::VerifyParamAttrs(const FunctionType *FT,
   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 @@ void Verifier::visitFunction(Function &F) {
           "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 @@ void Verifier::VerifyCallSite(CallSite CS) {
           "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);
     }
 
index 1f4c9c72b4048936aba32d8effdd29fbee3fd299..e8e9c41c6dfb76ab3b48c415a671707363472b84 100644 (file)
@@ -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
 }