llvm.org GIT mirror llvm / c14b5c3
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318279 91177308-0d34-0410-b5e6-96231b3b80d8 Mikael Holmen 2 years ago
2 changed file(s) with 51 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
284284 }
285285 }
286286
287 if (CS.isCall() && cast(CS.getInstruction())->isTailCall())
288 for (CallSite::arg_iterator AI = CS.arg_begin(), AE = CS.arg_end();
289 AI != AE; ++AI) {
290 Value *Obj = findValue(*AI, /*OffsetOk=*/true);
291 Assert(!isa(Obj),
292 "Undefined behavior: Call with \"tail\" keyword references "
293 "alloca",
294 &I);
295 }
287 if (CS.isCall()) {
288 const CallInst *CI = cast(CS.getInstruction());
289 if (CI->isTailCall()) {
290 const AttributeList &PAL = CI->getAttributes();
291 unsigned ArgNo = 0;
292 for (Value *Arg : CS.args()) {
293 // Skip ByVal arguments since they will be memcpy'd to the callee's
294 // stack anyway.
295 if (PAL.hasParamAttribute(ArgNo++, Attribute::ByVal))
296 continue;
297 Value *Obj = findValue(Arg, /*OffsetOk=*/true);
298 Assert(!isa(Obj),
299 "Undefined behavior: Call with \"tail\" keyword references "
300 "alloca",
301 &I);
302 }
303 }
304 }
296305
297306
298307 if (IntrinsicInst *II = dyn_cast(&I))
0 ; RUN: opt < %s -lint -disable-output 2>&1 | FileCheck %s
1
2 %s = type { i8 }
3
4 declare void @f1(%s*)
5
6 define void @f2() {
7 entry:
8 %c = alloca %s
9 tail call void @f1(%s* %c)
10 ret void
11 }
12
13 ; Lint should complain about the tail call passing the alloca'd value %c to f1.
14 ; CHECK: Undefined behavior: Call with "tail" keyword references alloca
15 ; CHECK-NEXT: tail call void @f1(%s* %c)
16
17 declare void @f3(%s* byval)
18
19 define void @f4() {
20 entry:
21 %c = alloca %s
22 tail call void @f3(%s* byval %c)
23 ret void
24 }
25
26 ; Lint should not complain about passing the alloca'd %c since it's passed
27 ; byval, effectively copying the data to the stack instead of leaking the
28 ; pointer itself.
29 ; CHECK-NOT: Undefined behavior: Call with "tail" keyword references alloca
30 ; CHECK-NOT: tail call void @f3(%s* byval %c)
31
32