From patchwork Thu Jul 5 11:25:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 939879 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-481039-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="HYwSlZBB"; dkim-atps=neutral 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 41LwXr0skJz9s29 for ; Thu, 5 Jul 2018 21:26:18 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=QkNsdtTXfevaSLmGM TWYV52r1LULKH3thWFru0jqvETrDWxnvu9/PtyurAd2EUAc57FhNVo9dZPAoJFCl Uuvfy+s+UtnCWb8DqW2EagOXEO1CIIpVtrj8oPjykeJncGVbSx2mXRC6ayg1wYAv +NRZeqPPSm9OGS5XN6q4XSUVNA= 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:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=cG4GnVWnCpEqVBwUZWOD/Vm W3hg=; b=HYwSlZBBKJ3OAum6w0hMStlGQfKs3n2xbCAQj9dTAqiIbiAqwzZJWO6 +G20+3JKk2hjrgkMO7/jNNGHUhATaAhbv6rUXRsCi8OtymLCM63iD/78lbobrOve XvxyCX31OVz5a89ooNaIqP/2+l9HXMouiEMfn1n0LAt2l27V+ODU= Received: (qmail 77742 invoked by alias); 5 Jul 2018 11:26:00 -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 77587 invoked by uid 89); 5 Jul 2018 11:25:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=27PM, 27pm, i_1, H*f:sk:948b1fd X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Jul 2018 11:25:58 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 84F00AD1E; Thu, 5 Jul 2018 11:25:55 +0000 (UTC) Date: Thu, 5 Jul 2018 13:25:58 +0200 From: Tom de Vries To: Jakub Jelinek , Richard Biener Cc: GCC Patches Subject: [PATCH][debug] Handle references to skipped params in remap_ssa_name Message-ID: <20180705112558.mphxe2sz7mozvcur@delia> References: <20180701161920.lzm5ikaiyr3pspxn@delia> <20180701191137.GQ7166@tucnak> <948b1fdd-9e53-2d65-7c72-99460a2fec1e@suse.de> <20180702081604.GR7166@tucnak> <2e0f12a5-803e-6f24-505e-574dd2ea4ba9@suse.de> <04c6e772-70f4-a786-13d9-7017382d7142@suse.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <04c6e772-70f4-a786-13d9-7017382d7142@suse.de> User-Agent: NeoMutt/20170912 (1.9.0) X-IsSubscribed: yes [ was: Re: [testsuite/guality, committed] Prevent optimization of local in vla-1.c ] On Wed, Jul 04, 2018 at 02:32:27PM +0200, Tom de Vries wrote: > On 07/03/2018 11:05 AM, Tom de Vries wrote: > > On 07/02/2018 10:16 AM, Jakub Jelinek wrote: > >> On Mon, Jul 02, 2018 at 09:44:04AM +0200, Richard Biener wrote: > >>> Given the array has size i + 1 it's upper bound should be 'i' and 'i' > >>> should be available via DW_OP_[GNU_]entry_value. > >>> > >>> I see it is > >>> > >>> <175> DW_AT_upper_bound : 10 byte block: 75 1 8 20 24 8 20 26 31 > >>> 1c (DW_OP_breg5 (rdi): 1; DW_OP_const1u: 32; DW_OP_shl; > >>> DW_OP_const1u: 32; DW_OP_shra; DW_OP_lit1; DW_OP_minus) > >>> > >>> and %rdi is 1. Not sure why gdb fails to print it's length. Yes, the > >>> storage itself doesn't have a location but the > >>> type specifies the size. > >>> > >>> (gdb) ptype a > >>> type = char [variable length] > >>> (gdb) p sizeof(a) > >>> $3 = 0 > >>> > >>> this looks like a gdb bug to me? > >>> > > > > With gdb patch: > > ... > > diff --git a/gdb/findvar.c b/gdb/findvar.c > > index 8ad5e25cb2..ebaff923a1 100644 > > --- a/gdb/findvar.c > > +++ b/gdb/findvar.c > > @@ -789,6 +789,8 @@ default_read_var_value > > break; > > > > case LOC_OPTIMIZED_OUT: > > + if (is_dynamic_type (type)) > > + type = resolve_dynamic_type (type, NULL, > > + /* Unused address. */ 0); > > return allocate_optimized_out_value (type); > > > > default: > > ... > > > > I get: > > ... > > $ ./gdb -batch -ex "b f1" -ex "r" -ex "p sizeof (a)" vla-1.exe > > Breakpoint 1 at 0x4004a8: file vla-1.c, line 17. > > > > Breakpoint 1, f1 (i=i@entry=5) at vla-1.c:17 > > 17 return a[0]; > > $1 = 6 > > ... > > > > Well, for -O1 and -O2. > > For O3, I get instead: > ... > $ ./gdb vla-1.exe -q -batch -ex "b f1" -ex "run" -ex "p sizeof (a)" > Breakpoint 1 at 0x4004b0: f1. (2 locations) > > Breakpoint 1, f1 (i=5) at vla-1.c:17 > 17 return a[0]; > $1 = 0 > ... > Hi, When compiling guality/vla-1.c with -O3 -g, vla 'a[i + 1]' in f1 is optimized away, but f1 still contains a debug expression describing the upper bound of the vla (D.1914): ... __attribute__((noinline)) f1 (intD.6 iD.1900) { saved_stack.1_2 = __builtin_stack_save (); # DEBUG BEGIN_STMT # DEBUG D#3 => i_1(D) + 1 # DEBUG D#2 => (long intD.8) D#3 # DEBUG D#1 => D#2 + -1 # DEBUG D.1914 => (sizetype) D#1 ... Then f1 is cloned to a version f1.constprop with no parameters, eliminating parameter i, and 'DEBUG D#3 => i_1(D) + 1' turns into 'D#3 => NULL'. Consequently, 'print sizeof (a)' yields '0' in gdb. This patch fixes that by recognizing eliminated parameters in remap_ssa_name, defining a debug expression linking back to the the eliminated parameter, and using that debug expression to replace references to the eliminated parameter: ... __attribute__((noinline)) f1.constprop () { intD.6 iD.1949; # DEBUG D#8 s=> iD.1900 # DEBUG iD.1949 => D#8 + # DEBUG D#6 s=> iD.1900 saved_stack.1_1 = __builtin_stack_save (); # DEBUG BEGIN_STMT - # DEBUG D#3 => NULL + # DEBUG D#3 => D#6 + 1 # DEBUG D#2 => (long intD.8) D#3 # DEBUG D#1 => D#2 + -1 # DEBUG D.1951 => (sizetype) D#1 ... The inserted debug expression (D#6) is a duplicate of the debug expression that will be inserted after copy_body in tree_function_versioning (D#8), so the patch contains a todo to fix the duplication. Bootstrapped and reg-tested on x86_64. OK for trunk? Thanks, - Tom [debug] Handle references to skipped params in remap_ssa_name 2018-07-05 Tom de Vries * tree-inline.c (remap_ssa_name): Handle references to skipped params. --- gcc/tree-inline.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 427ef959740..0fa996cab49 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -204,11 +204,22 @@ remap_ssa_name (tree name, copy_body_data *id) gimple *def_temp; gimple_stmt_iterator gsi; tree val = SSA_NAME_VAR (name); + bool skipped_parm_decl = false; n = id->decl_map->get (val); if (n != NULL) - val = *n; - if (TREE_CODE (val) != PARM_DECL) + { + if (TREE_CODE (*n) == DEBUG_EXPR_DECL) + return *n; + + if (TREE_CODE (*n) == VAR_DECL + && DECL_ABSTRACT_ORIGIN (*n) + && TREE_CODE (DECL_ABSTRACT_ORIGIN (*n)) == PARM_DECL) + skipped_parm_decl = true; + else + val = *n; + } + if (TREE_CODE (val) != PARM_DECL && !skipped_parm_decl) { processing_debug_stmt = -1; return name; @@ -219,6 +230,8 @@ remap_ssa_name (tree name, copy_body_data *id) SET_DECL_MODE (vexpr, DECL_MODE (SSA_NAME_VAR (name))); gsi = gsi_after_labels (single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun))); gsi_insert_before (&gsi, def_temp, GSI_SAME_STMT); + // Todo: Reuse vexpr in tree_function_versioning + insert_decl_map (id, val, vexpr); return vexpr; }