aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2008-01-12 16:42:01 +0000
committerDuncan Sands <baldrick@free.fr>2008-01-12 16:42:01 +0000
commitcfad1b4f783bfafaeb102e3358594dc23940a490 (patch)
treee7f475181d96a43ed29fbd583457a2c71583449f
parent120d053e3ba810b44047fbcb719824bed5673ca9 (diff)
Be more liberal in what parameter attributes are
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
-rw-r--r--include/llvm/ParameterAttributes.h4
-rw-r--r--lib/VMCore/Verifier.cpp76
-rw-r--r--test/Verifier/2008-01-11-VarargAttrs.ll4
3 files changed, 49 insertions, 35 deletions
diff --git a/include/llvm/ParameterAttributes.h b/include/llvm/ParameterAttributes.h
index 4106dcb290..ded847e146 100644
--- a/include/llvm/ParameterAttributes.h
+++ b/include/llvm/ParameterAttributes.h
@@ -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] = {
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp
index e42109e0f3..626119b437 100644
--- a/lib/VMCore/Verifier.cpp
+++ b/lib/VMCore/Verifier.cpp
@@ -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);
}
diff --git a/test/Verifier/2008-01-11-VarargAttrs.ll b/test/Verifier/2008-01-11-VarargAttrs.ll
index 1f4c9c72b4..e8e9c41c6d 100644
--- a/test/Verifier/2008-01-11-VarargAttrs.ll
+++ b/test/Verifier/2008-01-11-VarargAttrs.ll
@@ -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
}