Skip to content

Commit 031126c

Browse files
committed
Merge 64364 from mainline.
Fix a nasty bug (PR3550) where the inline pass could incorrectly mark calls with the tail marker when inlining them through an invoke. Patch, testcase, and perfect analysis by Jay Foad! llvm-svn: 64520
1 parent 904dbdb commit 031126c

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,10 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
203203
CalledFunc->getFunctionType()->isVarArg()) return false;
204204

205205

206-
// If the call to the callee is a non-tail call, we must clear the 'tail'
206+
// If the call to the callee is not a tail call, we must clear the 'tail'
207207
// flags on any calls that we inline.
208208
bool MustClearTailCallFlags =
209-
isa<CallInst>(TheCall) && !cast<CallInst>(TheCall)->isTailCall();
209+
!(isa<CallInst>(TheCall) && cast<CallInst>(TheCall)->isTailCall());
210210

211211
// If the call to the callee cannot throw, set the 'nounwind' flag on any
212212
// calls that we inline.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; RUN: llvm-as < %s | opt -inline | llvm-dis | not grep {tail call void @llvm.memcpy.i32}
2+
; PR3550
3+
4+
define internal void @foo(i32* %p, i32* %q) {
5+
%pp = bitcast i32* %p to i8*
6+
%qq = bitcast i32* %q to i8*
7+
tail call void @llvm.memcpy.i32(i8* %pp, i8* %qq, i32 4, i32 1)
8+
ret void
9+
}
10+
11+
declare void @llvm.memcpy.i32(i8* nocapture, i8* nocapture, i32, i32) nounwind
12+
13+
define i32 @main() {
14+
%a = alloca i32 ; <i32*> [#uses=3]
15+
%b = alloca i32 ; <i32*> [#uses=2]
16+
store i32 1, i32* %a, align 4
17+
store i32 0, i32* %b, align 4
18+
invoke void @foo(i32* %a, i32* %b)
19+
to label %invcont unwind label %lpad
20+
21+
invcont:
22+
%retval = load i32* %a, align 4
23+
ret i32 %retval
24+
25+
lpad:
26+
%eh_ptr = call i8* @llvm.eh.exception()
27+
%eh_select = call i32 (i8*, i8*, ...)* @llvm.eh.selector.i32(i8* %eh_ptr, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* null)
28+
unreachable
29+
}
30+
31+
declare i8* @llvm.eh.exception() nounwind
32+
33+
declare i32 @llvm.eh.selector.i32(i8*, i8*, ...) nounwind
34+
35+
declare i32 @__gxx_personality_v0(...)

0 commit comments

Comments
 (0)