Diagnose uses of unsized types with the byval attribute in the
authorDan Gohman <gohman@apple.com>
Wed, 27 Aug 2008 14:48:06 +0000 (14:48 +0000)
committerDan Gohman <gohman@apple.com>
Wed, 27 Aug 2008 14:48:06 +0000 (14:48 +0000)
verifier. See PR2711 for details.

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

lib/VMCore/Verifier.cpp
test/Verifier/byval-2.ll

index 299a0f4043c4b881114fd208b7257218a5ae1e23..84f9499168976914acfd4426282a2a0fc211deb8 100644 (file)
@@ -421,6 +421,17 @@ void Verifier::VerifyAttrs(ParameterAttributes Attrs, const Type *Ty,
   ParameterAttributes TypeI = Attrs & ParamAttr::typeIncompatible(Ty);
   Assert1(!TypeI, "Wrong type for attribute " +
           ParamAttr::getAsString(TypeI), V);
+
+  ParameterAttributes ByValI = Attrs & ParamAttr::ByVal;
+  if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) {
+    Assert1(!ByValI || PTy->getElementType()->isSized(),
+            "Attribute " + ParamAttr::getAsString(ByValI) +
+            " does not support unsized types!", V);
+  } else {
+    Assert1(!ByValI,
+            "Attribute " + ParamAttr::getAsString(ByValI) +
+            " only applies to parameters with pointer type!", V);
+  }
 }
 
 // VerifyFunctionAttrs - Check parameter attributes against a function type.
index d7bfedfcd6a6ea9c712bd878daa11e210fe5e874..1d03715bc3228818c021c0352e399077cb969b96 100644 (file)
@@ -1,3 +1,4 @@
-; RUN: llvm-as %s -o /dev/null -f
+; RUN: not llvm-as < %s >& /dev/null
+; PR2711
        %s = type opaque
 declare void @h(%s* byval %num)