From patchwork Wed Nov 18 00:32:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 56908 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp2260020lbb; Tue, 17 Nov 2015 16:32:53 -0800 (PST) X-Received: by 10.68.65.74 with SMTP id v10mr67386131pbs.67.1447806773489; Tue, 17 Nov 2015 16:32:53 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id tk2si158918pab.196.2015.11.17.16.32.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Nov 2015 16:32:53 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-414441-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-return-414441-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-414441-patch=linaro.org@gcc.gnu.org; dkim=pass header.i=@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:references:cc:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=HBoWtXAui9jAgboXs MmSOyV/HV8Xa2Lpy5iUfCL/Cy2T/PpYoRom21ZMyjCVKxotBSQwKXAW3n8Sloecp PUxPtEkCxFc4bURFRWxlIX2mm9s4cenfIx7HpClknA8FZ/NQd23Pjz2yDtxlEPxW Bzoi9HoK0BEHdr/DB68lSbG+9w= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:references:cc:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=wag8Js/2AqMJv7upXwDudB5 oCeY=; b=vUEyvSOhxEMFr7iBvHBRvWaPMFARtuZDVGBlHlj1AiPKKbs059tBTB1 c4okv1sxvz8WmZOgDPRQnnxXUJIZtAekuG9gNqRA7QSFAZlasnQUpLTfWid8Dr5y /UGVbCEZ3tpv9lfci8aZzsCuWGCEmJozvZbAXPNout1prYdTHHNU= Received: (qmail 31079 invoked by alias); 18 Nov 2015 00:32:38 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 31065 invoked by uid 89); 18 Nov 2015 00:32:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f45.google.com Received: from mail-pa0-f45.google.com (HELO mail-pa0-f45.google.com) (209.85.220.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 18 Nov 2015 00:32:36 +0000 Received: by padhx2 with SMTP id hx2so24929693pad.1 for ; Tue, 17 Nov 2015 16:32:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:references:cc:message-id:date :user-agent:mime-version:in-reply-to:content-type; bh=qzIUuFy70MUVFQFVMG0IUzFfcRc4nqGE4IMrfMKxpv4=; b=lNrmi9+w9AcrF6ZZAGtFqFMUvVBVkpCr6UpW6eHSbHB/NCsLE8pCYOwUQ8KE6Bl6eV HC8kyH20ZS1r3aPit/lWF/wJd3WpFM8maATLMGlCnUW+81EJXlfhzk3NPL/Shcc27PCS aDWk8+8j1W+Gz/2YmXpRS286eoGIgSlaDkeJwtC2RfAcZMNKjxZxrSBxN1p23rUaw/rJ pxwaYDPtfZOEnloZ+l3CdEEK9mvLEM9LN4zxjCyTce3idG5cDLOBUCpdpBXW2QI3BPu7 Xu7BkQdLwHhqjvFoSNQ2NgV5BP9pv8eLZrmxagc029VZMMNPw787vpLZxaRjd4yAvxR/ OyjQ== X-Gm-Message-State: ALoCoQm74chwagg+1Zvr3DWhqhpSv7EcpWxEQCqBRRXCTsA9J9oLKQF2uyGseaRGvg1gxHXvF+6P X-Received: by 10.66.160.194 with SMTP id xm2mr68219460pab.68.1447806754441; Tue, 17 Nov 2015 16:32:34 -0800 (PST) Received: from [10.1.1.10] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by smtp.googlemail.com with ESMTPSA id dd4sm84684pbb.52.2015.11.17.16.32.30 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 17 Nov 2015 16:32:33 -0800 (PST) From: Kugan Subject: Re: Incorrect code due to indirect tail call of varargs function with hard float ABI To: Ramana Radhakrishnan , Charles Baylis References: <564A57BA.7050504@linaro.org> <564A9327.8070607@linaro.org> <564AFBEE.9050801@foss.arm.com> <564B8655.1060509@linaro.org> Cc: "gcc-patches@gcc.gnu.org" , Richard Earnshaw , Ramana Radhakrishnan , Kyrill Tkachov Message-ID: <564BC70C.70805@linaro.org> Date: Wed, 18 Nov 2015 11:32:12 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <564B8655.1060509@linaro.org> X-IsSubscribed: yes > Hi Ramana, > > Thanks for the review. I have opened a gcc bug-report for this. I tested > the attached patch for arm-none-linux-gnueabihf and > arm-none-linux-gnueabi with no new regressions. Is this OK? > > > Thanks, > Kugan > > gcc/ChangeLog: > > 2015-11-18 Kugan Vivekanandarajah > > PR target/68390 > * config/arm/arm.c (arm_function_ok_for_sibcall): Get function type > for indirect function call. > > gcc/testsuite/ChangeLog: > > 2015-11-18 Kugan Vivekanandarajah > > PR target/68390 > * gcc.target/arm/PR68390.c: New test. > > Hi Ramana, With further testing on bare-metal, I found that for the following decl has to be null for indirect functions. if (TARGET_AAPCS_BASED && arm_abi == ARM_ABI_AAPCS && decl && DECL_WEAK (decl)) return false; Here is the updated patch and ChangeLog. Sorry for the noise. Thanks, Kugan gcc/ChangeLog: 2015-11-18 Kugan Vivekanandarajah PR target/68390 * config/arm/arm.c (arm_function_ok_for_sibcall): Get function type for indirect function call. gcc/testsuite/ChangeLog: 2015-11-18 Kugan Vivekanandarajah PR target/68390 * gcc.target/arm/PR68390.c: New test. diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index a379121..0dae7da 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -6680,8 +6680,13 @@ arm_function_ok_for_sibcall (tree decl, tree exp) a VFP register but then need to transfer it to a core register. */ rtx a, b; + tree fn_decl = decl; - a = arm_function_value (TREE_TYPE (exp), decl, false); + /* If it is an indirect function pointer, get the function type. */ + if (!decl) + fn_decl = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (exp))); + + a = arm_function_value (TREE_TYPE (exp), fn_decl, false); b = arm_function_value (TREE_TYPE (DECL_RESULT (cfun->decl)), cfun->decl, false); if (!rtx_equal_p (a, b)) diff --git a/gcc/testsuite/gcc.target/arm/PR68390.c b/gcc/testsuite/gcc.target/arm/PR68390.c index e69de29..86f07fe 100644 --- a/gcc/testsuite/gcc.target/arm/PR68390.c +++ b/gcc/testsuite/gcc.target/arm/PR68390.c @@ -0,0 +1,27 @@ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +__attribute__ ((noinline)) +double direct(int x, ...) +{ + return x*x; +} + +__attribute__ ((noinline)) +double broken(double (*indirect)(int x, ...), int v) +{ + return indirect(v); +} + +int main () +{ + double d1, d2; + int i = 2; + d1 = broken (direct, i); + if (d1 != i*i) + { + __builtin_abort (); + } + return 0; +} +