From patchwork Wed Jul 1 21:57:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1320854 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49xw823f4zz9sRW for ; Thu, 2 Jul 2020 07:57:53 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 419DF3861817; Wed, 1 Jul 2020 21:57:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 98CD93857007 for ; Wed, 1 Jul 2020 21:57:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 98CD93857007 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mjambor@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 122D3AD3A for ; Wed, 1 Jul 2020 21:57:46 +0000 (UTC) From: Martin Jambor To: GCC Patches Subject: [PATCH] ipa-sra: Prevent constructing debug info from wrong argument User-Agent: Notmuch/0.29.3 (https://notmuchmail.org) Emacs/26.3 (x86_64-suse-linux-gnu) Date: Wed, 01 Jul 2020 23:57:45 +0200 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-3038.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Hubicka Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, the mechanism generating debug info for removed parameters did not adjust index of the argument in the call statement to take into account extra arguments IPA-SRA might have produced when splitting a strucutre. This patch addresses that omission and stops gdb from showing incorrect value for the removed parameter and says "value optimized out" instead. The guality testcase will end up as UNSUPPORTED in the results which is how Richi told me on IRC we deal with this. It is possible to generate debug info to actually show the value of the removed parameter but so far my approaches to do that seem too controversial (https://gcc.gnu.org/pipermail/gcc-patches/2020-May/546705.html), so before I come up with something better I'd like to push this to master and the gcc-10 branch in time for the GCC 10.2 release. Bootstrapped and tested on master on x86_64-linux, bootstrap on top of the gcc-10 branch is underway? OK for both if it passes? Thanks, Martin gcc/ChangeLog: 2020-07-01 Martin Jambor PR guality/95343 * ipa-param-manipulation.c (ipa_param_adjustments::modify_call): Adjust argument index if necessary. gcc/testsuite/ChangeLog: 2020-07-01 Martin Jambor PR guality/95343 * gcc.dg/guality/pr95343.c: New test. --- gcc/ipa-param-manipulation.c | 6 +++- gcc/testsuite/gcc.dg/guality/pr95343.c | 45 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/guality/pr95343.c diff --git a/gcc/ipa-param-manipulation.c b/gcc/ipa-param-manipulation.c index 2cc4bc79dc1..5fc0de56556 100644 --- a/gcc/ipa-param-manipulation.c +++ b/gcc/ipa-param-manipulation.c @@ -790,7 +790,11 @@ ipa_param_adjustments::modify_call (gcall *stmt, if (!is_gimple_reg (old_parm) || kept[i]) continue; tree origin = DECL_ORIGIN (old_parm); - tree arg = gimple_call_arg (stmt, i); + tree arg; + if (transitive_remapping) + arg = gimple_call_arg (stmt, index_map[i]); + else + arg = gimple_call_arg (stmt, i); if (!useless_type_conversion_p (TREE_TYPE (origin), TREE_TYPE (arg))) { diff --git a/gcc/testsuite/gcc.dg/guality/pr95343.c b/gcc/testsuite/gcc.dg/guality/pr95343.c new file mode 100644 index 00000000000..a3e57decda8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/guality/pr95343.c @@ -0,0 +1,45 @@ +/* { dg-do run } */ +/* { dg-options "-g -fno-ipa-icf" } */ + +volatile int v; + +int __attribute__((noipa)) +get_val0 (void) {return 0;} +int __attribute__((noipa)) +get_val2 (void) {return 2;} + +struct S +{ + int a, b, c; +}; + +static int __attribute__((noinline)) +bar (struct S s, int x, int y, int z, int i) +{ + int r; + v = s.a + s.b; /* { dg-final { gdb-test . "i+1" "3" } } */ + return r; +} + +static int __attribute__((noinline)) +foo (struct S s, int i) +{ + int r; + r = bar (s, 3, 4, 5, i); + return r; +} + + +int +main (void) +{ + struct S s; + int i; + i = get_val2 (); + s.a = get_val0 (); + s.b = get_val0 (); + s.c = get_val0 (); + int r = foo (s, i); + v = r + i; + return 0; +}