]> granicus.if.org Git - llvm/commitdiff
[IPCP] Don't propagate return value for naked functions.
authorDavide Italiano <davide@freebsd.org>
Sat, 4 Feb 2017 19:44:14 +0000 (19:44 +0000)
committerDavide Italiano <davide@freebsd.org>
Sat, 4 Feb 2017 19:44:14 +0000 (19:44 +0000)
This is pretty much the same change made in SCCP.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294098 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/IPConstantPropagation.cpp
test/Transforms/IPConstantProp/naked-return.ll

index 916135e33cd50544c6e8c162e100ef2cfde66a14..349807496dc2c0dc0f8cd188a76aa61275d64dcc 100644 (file)
@@ -136,7 +136,13 @@ static bool PropagateConstantReturn(Function &F) {
   // For more details, see GlobalValue::mayBeDerefined.
   if (!F.isDefinitionExact())
     return false;
-    
+
+  // Don't touch naked functions. The may contain asm returning
+  // value we don't see, so we may end up interprocedurally propagating
+  // the return value incorrectly.
+  if (F.hasFnAttribute(Attribute::Naked))
+    return false;
+
   // Check to see if this function returns a constant.
   SmallVector<Value *,4> RetVals;
   StructType *STy = dyn_cast<StructType>(F.getReturnType());
index ef4747175e032de34e1d95c3c715bbeabcfd3d1e..3a2dedafcd3758b002c3068eb59a1c3864c8c10d 100644 (file)
@@ -1,4 +1,5 @@
 ; RUN: opt -ipsccp -S %s | FileCheck %s
+; RUN: opt -ipconstprop -S %s | FileCheck %s
 
 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
 target triple = "i686-pc-windows-msvc19.0.24215"