From patchwork Mon Nov 16 22:24:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 56695 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp1586367lbb; Mon, 16 Nov 2015 14:25:41 -0800 (PST) X-Received: by 10.68.165.131 with SMTP id yy3mr13618654pbb.163.1447712740627; Mon, 16 Nov 2015 14:25:40 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id dm1si20016782pbc.117.2015.11.16.14.25.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Nov 2015 14:25:40 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-414290-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-414290-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-414290-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:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=bTPBuLPkM3A/fuEz2bch5CDXAsNx6G9DmwvHvCkWNFNY9UXGL/ CGxX+KveMUg/vD6qx08trbO9DpLVakq+CFkcfBJ5ctwQpJJXIp8ubxFD7a1ajWt2 16l5jtLCa/0S4LGZTAWuS1fXkn3+dCFJ+95X84i3emcbrQUVeNvCb+gp8= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=5mTX5DpMyaIdLe2r6+nJ2A1klmQ=; b=jRfn/YRYGCdEwyIfUdYG 8LIX7K8i5FnfwVOnoldBXVY2UO/yKBfKb7HrF6Xlio+Y6nk1j7DMp8uXnMmtK63x GzKR3BF/lk0JhkBMueM4h3Ix7kP7NqXutntdzvV0eDrS9IKbYe7F9JBVd7cNPwPk VF1cxP0gYB48hT99uhIygws= Received: (qmail 41233 invoked by alias); 16 Nov 2015 22:25:22 -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 41223 invoked by uid 89); 16 Nov 2015 22:25:21 -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-f46.google.com Received: from mail-pa0-f46.google.com (HELO mail-pa0-f46.google.com) (209.85.220.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 16 Nov 2015 22:25:20 +0000 Received: by pabfh17 with SMTP id fh17so191294951pab.0 for ; Mon, 16 Nov 2015 14:25:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-type; bh=RM8QUVuzP1kYhO5jiPO7tUCOrg+8F4FzrgEdrlM1wlc=; b=lcwckao31QIWY5lnWIvKjjMACsozUI727gyrPN/Vb1Di2Yle/8wb8Z8+pZCqB8nap0 H2vJQtQkY6UWLwrt7t0+DNxcbMOp+xHzWvSRSw6D7Tf9JLLEZ2iZzbxPTi2qc68lzRpz Mj7Ab1cZMdNd4GvnJfRIQeKkLCUdZk5lgGu732fpb1elRY3/ngsHjZ1VmBBtvFtZ3pgU Ba3xk4LTtirI9l1BZAwHrxqLS2UnF0To6gBCyNGo7BJVo5XiiVRj5OHmYzhmZ+gAJXuA YBh+0ICi0dG3pMk4XI+cy/8aGHYOyRhbGCyFtpC0JZmJsOXzhgQPkVQsN7oL3/pPhowe NyJQ== X-Gm-Message-State: ALoCoQnSHOP1jkpwoEmQ4Ghwk/L9/3dvdNN5NJvpVm5H+1GLkXY9AprAfOi0Vdsx9drs0eAv2bJF X-Received: by 10.66.101.40 with SMTP id fd8mr49809713pab.91.1447712718348; Mon, 16 Nov 2015 14:25:18 -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 hz4sm24185827pbc.12.2015.11.16.14.25.15 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 16 Nov 2015 14:25:17 -0800 (PST) To: "gcc-patches@gcc.gnu.org" Cc: Richard Earnshaw , Ramana Radhakrishnan , Kyrill Tkachov From: Kugan Subject: Incorrect code due to indirect tail call of varargs function with hard float ABI Message-ID: <564A57BA.7050504@linaro.org> Date: Tue, 17 Nov 2015 09:24:58 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 X-IsSubscribed: yes Following testcase fails on ARM (from https://bugs.linaro.org/show_bug.cgi?id=1900). __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; } Please note that we have a sibcall from "broken" to "indirect". "direct" is variadic function so it is conforming to AAPCS base standard. "broken" is a non-variadic function and will return the value in floating point register for TARGET_HARD_FLOAT. Thus we should not be doing sibcall here. Attached patch fixes this. Bootstrap and regression testing is ongoing. Is this OK if no issues with the testing? Thanks, Kugan gcc/ChangeLog: 2015-11-17 Kugan Vivekanandarajah * config/arm/arm.c (arm_function_ok_for_sibcall): Disable sibcall to indirect function when TARGET_HARD_FLOAT. gcc/testsuite/ChangeLog: 2015-11-17 Kugan Vivekanandarajah * gcc.target/arm/variadic_sibcall.c: New test. diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index a379121..8b560bc 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -6681,6 +6681,12 @@ arm_function_ok_for_sibcall (tree decl, tree exp) register. */ rtx a, b; + /* When it is an indirect call (i.e, decl == NULL), it could be + returning its result in a VFP or could be a variadic function. + Thus return false. */ + if (!decl && TARGET_HARD_FLOAT) + return false; + a = arm_function_value (TREE_TYPE (exp), decl, false); b = arm_function_value (TREE_TYPE (DECL_RESULT (cfun->decl)), cfun->decl, false); diff --git a/gcc/testsuite/gcc.target/arm/variadic_sibcall.c b/gcc/testsuite/gcc.target/arm/variadic_sibcall.c index e69de29..86f07fe 100644 --- a/gcc/testsuite/gcc.target/arm/variadic_sibcall.c +++ b/gcc/testsuite/gcc.target/arm/variadic_sibcall.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; +} +