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: 545214 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C8F90141468 for ; Tue, 17 Nov 2015 09:25:31 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=aGAZ0KRg; dkim-atps=neutral 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=D7a3SrwElx8Yz6evqWdCSCiQLVLuz7Kg98oZ+zn43ODV/EBYWa QI+XljJWvFDHS3fLQYiXkItfK1H3iUsUi0kJL/NaKas9LbovPE6N4HCjfBXddHQ3 RoLRdzhQ+XJ5i1Z22sqV4NeB/kRJDXQSLv57LpDXGoDvecMISdCz5QfQM= 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=aGAZ0KRg/QzRnUlzgtYk Go6Kk2pJgYUZkpWK/Cl0c2NRziJfkgIfCiwtMuuYDEP3dyVBEy5m0iBJ5Ghpr+y1 8p+H89BPaR7ODCAOpr/0jCBND2s3w5Z7aH8lGXgZjUZ/ahSSYBz6qcJm463/dVcO xJQ5SQceDrT0LyS/2xdWLg0= 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; +} +