From 6e60297ee6ba465197db443f8eaa88315ba36ac4 Mon Sep 17 00:00:00 2001 From: Mikael Holmen Date: Wed, 15 Nov 2017 07:46:48 +0000 Subject: [Lint] Don't warn about passing alloca'd value to tail call if using byval Summary: This fixes PR35241. When using byval, the data is effectively copied as part of the call anyway, so the pointer returned by the alloca will not be leaked to the callee and thus there is no reason to issue a warning. Reviewers: rnk Reviewed By: rnk Subscribers: Ka-Ka, llvm-commits Differential Revision: https://reviews.llvm.org/D40009 llvm-svn: 318279 --- llvm/lib/Analysis/Lint.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'llvm/lib/Analysis/Lint.cpp') diff --git a/llvm/lib/Analysis/Lint.cpp b/llvm/lib/Analysis/Lint.cpp index ae92f502f5c..7b792ed0a2e 100644 --- a/llvm/lib/Analysis/Lint.cpp +++ b/llvm/lib/Analysis/Lint.cpp @@ -285,15 +285,24 @@ void Lint::visitCallSite(CallSite CS) { } } - if (CS.isCall() && cast(CS.getInstruction())->isTailCall()) - for (CallSite::arg_iterator AI = CS.arg_begin(), AE = CS.arg_end(); - AI != AE; ++AI) { - Value *Obj = findValue(*AI, /*OffsetOk=*/true); - Assert(!isa(Obj), - "Undefined behavior: Call with \"tail\" keyword references " - "alloca", - &I); + if (CS.isCall()) { + const CallInst *CI = cast(CS.getInstruction()); + if (CI->isTailCall()) { + const AttributeList &PAL = CI->getAttributes(); + unsigned ArgNo = 0; + for (Value *Arg : CS.args()) { + // Skip ByVal arguments since they will be memcpy'd to the callee's + // stack anyway. + if (PAL.hasParamAttribute(ArgNo++, Attribute::ByVal)) + continue; + Value *Obj = findValue(Arg, /*OffsetOk=*/true); + Assert(!isa(Obj), + "Undefined behavior: Call with \"tail\" keyword references " + "alloca", + &I); + } } + } if (IntrinsicInst *II = dyn_cast(&I)) -- cgit v1.2.3