llvm.org GIT mirror llvm / fb36e6d
[IPSCCP] Teach how to not propagate return values of naked functions. Differential Revision: https://reviews.llvm.org/D29360 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293727 91177308-0d34-0410-b5e6-96231b3b80d8 Davide Italiano 2 years ago
2 changed file(s) with 32 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
17111711
17121712 // If this is an exact definition of this function, then we can propagate
17131713 // information about its result into callsites of it.
1714 if (F.hasExactDefinition())
1714 // Don't touch naked functions. They may contain asm returning a
1715 // value we don't see, so we may end up interprocedurally propagating
1716 // the return value incorrectly.
1717 if (F.hasExactDefinition() && !F.hasFnAttribute(Attribute::Naked))
17151718 Solver.AddTrackedFunction(&F);
17161719
17171720 // If this function only has direct calls that we can see, we can track its
0 ; RUN: opt -ipsccp -S %s | FileCheck %s
1
2 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
3 target triple = "i686-pc-windows-msvc19.0.24215"
4
5 define i32 @dipsy(i32, i32) local_unnamed_addr #0 {
6 BasicBlock0:
7 call void asm "\0D\0Apushl %ebp\0D\0Amovl 8(%esp),%eax\0D\0Amovl 12(%esp), %ebp\0D\0Acalll *%eax\0D\0Apopl %ebp\0D\0Aretl\0D\0A", ""()
8 ret i32 0
9 }
10
11 define void @tinkywinky(i32, i32, i32) local_unnamed_addr #0 {
12 BasicBlock1:
13 call void asm "\0D\0A movl 12(%esp), %ebp\0D\0A movl 4(%esp), %eax\0D\0A movl 8(%esp), %esp\0D\0A jmpl *%eax\0D\0A", ""()
14 ret void
15 }
16
17 define void @patatino(i32, i32, i32) local_unnamed_addr #1 {
18 bb:
19 %3 = tail call i32 @dipsy(i32 %0, i32 %1) #0
20 ; Check that we don't accidentally propagate zero.
21 ; CHECK: @tinkywinky(i32 %3, i32 %2, i32 %1) #0
22 tail call void @tinkywinky(i32 %3, i32 %2, i32 %1) #0
23 ret void
24 }
25
26 attributes #0 = { naked noinline optnone }
27 attributes #1 = { "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" }