From 6c70dc7842fdc036de1a49a8f62026f5cd6d0c23 Mon Sep 17 00:00:00 2001 From: Stephen Lin Date: Tue, 23 Apr 2013 16:31:56 +0000 Subject: [PATCH] Add some constraints to use of 'returned': 1) Disallow 'returned' on parameter that is also 'sret' (no sensible semantics, as far as I can tell). 2) Conservatively disallow tail calls through 'returned' parameters that also are 'zext' or 'sext' (for consistency with treatment of other zero-extending and sign-extending operations in tail call position detection...can be revised later to handle situations that can be determined to be safe). This is a new attribute that is not yet used, so there is no impact. llvm-svn: 180118 --- llvm/lib/CodeGen/Analysis.cpp | 4 ++++ llvm/lib/IR/Verifier.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/llvm/lib/CodeGen/Analysis.cpp b/llvm/lib/CodeGen/Analysis.cpp index 4731af5089ac..e2b2067b0c65 100644 --- a/llvm/lib/CodeGen/Analysis.cpp +++ b/llvm/lib/CodeGen/Analysis.cpp @@ -269,6 +269,8 @@ static bool sameNoopInput(const Value *V1, const Value *V2, i != e; ++i) { unsigned attrInd = i - I->op_begin() + 1; if (cast(I)->paramHasAttr(attrInd, Attribute::Returned) && + !cast(I)->paramHasAttr(attrInd, Attribute::ZExt) && + !cast(I)->paramHasAttr(attrInd, Attribute::SExt) && isNoopBitcast((*i)->getType(), I->getType(), TLI)) { NoopInput = *i; break; @@ -282,6 +284,8 @@ static bool sameNoopInput(const Value *V1, const Value *V2, i != e; ++i) { unsigned attrInd = i - I->op_begin() + 1; if (cast(I)->paramHasAttr(attrInd, Attribute::Returned) && + !cast(I)->paramHasAttr(attrInd, Attribute::ZExt) && + !cast(I)->paramHasAttr(attrInd, Attribute::SExt) && isNoopBitcast((*i)->getType(), I->getType(), TLI)) { NoopInput = *i; break; diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 888090db61e0..d106173b5212 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -740,6 +740,10 @@ void Verifier::VerifyParameterAttrs(AttributeSet Attrs, unsigned Idx, Type *Ty, Attrs.hasAttribute(Idx, Attribute::InReg))), "Attributes " "'byval, nest, and inreg' are incompatible!", V); + Assert1(!(Attrs.hasAttribute(Idx, Attribute::StructRet) && + Attrs.hasAttribute(Idx, Attribute::Returned)), "Attributes " + "'sret and returned' are incompatible!", V); + Assert1(!(Attrs.hasAttribute(Idx, Attribute::ZExt) && Attrs.hasAttribute(Idx, Attribute::SExt)), "Attributes " "'zeroext and signext' are incompatible!", V);