From patchwork Wed Jan 3 20:42:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 855208 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-470101-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ZL+Vx9LG"; 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 3zBjXr5NT1z9s1h for ; Thu, 4 Jan 2018 07:42:17 +1100 (AEDT) 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:reply-to:mime-version :content-type; q=dns; s=default; b=ym+kleHTSSrwAdpBCSaPldbiXabfe Ou2Gi47yWfUzsfrkRGWvBerV9+lmfztB/rhDvFoGxZTChxn8XPu5+o0cwaqixUaW zhIh1GGR4Xk7AIUTReD9x+q3tJoGarx0pxqwpbFvuTE5avGn1p7riBpdcWBAIuxi Zi41D89LgY3ZMM= 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:reply-to:mime-version :content-type; s=default; bh=jVk55rTRNVogUGJ1dNnPzQfU3VI=; b=ZL+ Vx9LGA7Z8MmmCIGW5frF9Db1HQ/3VU7xERmcSR3KxB3cDV9Jd4gRrBC6v9Zw8WFB yQghHXx5W8zA9SxGo4OEXbR1oDFnbq3Vm1rnsjKpImUb+CAqJPoOaSMVTNLKGvdh TZZAB0ad9k2J1bHTObI/TPiyMlrfbRIgpVef9a0E= Received: (qmail 53961 invoked by alias); 3 Jan 2018 20:42:10 -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 53946 invoked by uid 89); 3 Jan 2018 20:42:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=var-tracking.c, UD:var-tracking.c, UD:stor-layout.c, sk:debug_m X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 03 Jan 2018 20:42:08 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B44A5C0587FA; Wed, 3 Jan 2018 20:42:06 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-90.ams2.redhat.com [10.36.116.90]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 01A705C548; Wed, 3 Jan 2018 20:42:05 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id w03Kg2gk025113; Wed, 3 Jan 2018 21:42:02 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w03Kg1B2025112; Wed, 3 Jan 2018 21:42:01 +0100 Date: Wed, 3 Jan 2018 21:42:01 +0100 From: Jakub Jelinek To: Richard Biener , Jeff Law , Alexandre Oliva Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix ICE with statement frontiers (PR debug/83645) Message-ID: <20180103204201.GL1833@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) X-IsSubscribed: yes Hi! When var-tracking pass isn't done (e.g. with -O2 -g -fno-var-tracking or -O2 -gstatement-frontiers), rest_of_handle_final calls variable_tracking_main in order to perform delete_vta_debug_insns - replace the debug marker insns with notes. The problem with that is that final pass is after freeing cfg, so using FOR_EACH_BB/FOR_BB_INSNS_SAFE is incorrect as the attached patch shows, e.g. the barriers pass swaps a barrier with the statement notes and nothing updates the bb boundaries. Fixed by doing the replacements on the raw insn stream when called from final.c. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2018-01-03 Jakub Jelinek PR debug/83645 * var-tracking.c (delete_vta_debug_insn): New inline function. (delete_vta_debug_insns): Add USE_CFG argument, if true, walk just insns from get_insns () to NULL instead of each bb separately. Use delete_vta_debug_insn. No longer static. (vt_debug_insns_local, variable_tracking_main_1): Adjust delete_vta_debug_insns callers. * rtl.h (delete_vta_debug_insns): Declare. * final.c (rest_of_handle_final): Call delete_vta_debug_insns instead of variable_tracking_main. * gcc.dg/pr83645.c: New test. Jakub --- gcc/var-tracking.c.jj 2018-01-03 10:19:54.385533834 +0100 +++ gcc/var-tracking.c 2018-01-03 16:01:48.608217538 +0100 @@ -10271,11 +10271,40 @@ vt_initialize (void) static int debug_label_num = 1; +/* Remove from the insn stream a single debug insn used for + variable tracking at assignments. */ + +static inline void +delete_vta_debug_insn (rtx_insn *insn) +{ + if (DEBUG_MARKER_INSN_P (insn)) + { + reemit_marker_as_note (insn); + return; + } + + tree decl = INSN_VAR_LOCATION_DECL (insn); + if (TREE_CODE (decl) == LABEL_DECL + && DECL_NAME (decl) + && !DECL_RTL_SET_P (decl)) + { + PUT_CODE (insn, NOTE); + NOTE_KIND (insn) = NOTE_INSN_DELETED_DEBUG_LABEL; + NOTE_DELETED_LABEL_NAME (insn) + = IDENTIFIER_POINTER (DECL_NAME (decl)); + SET_DECL_RTL (decl, insn); + CODE_LABEL_NUMBER (insn) = debug_label_num++; + } + else + delete_insn (insn); +} + /* Remove from the insn stream all debug insns used for variable - tracking at assignments. */ + tracking at assignments. USE_CFG should be false if the cfg is no + longer usable. */ -static void -delete_vta_debug_insns (void) +void +delete_vta_debug_insns (bool use_cfg) { basic_block bb; rtx_insn *insn, *next; @@ -10283,33 +10312,20 @@ delete_vta_debug_insns (void) if (!MAY_HAVE_DEBUG_INSNS) return; - FOR_EACH_BB_FN (bb, cfun) - { - FOR_BB_INSNS_SAFE (bb, insn, next) + if (use_cfg) + FOR_EACH_BB_FN (bb, cfun) + { + FOR_BB_INSNS_SAFE (bb, insn, next) + if (DEBUG_INSN_P (insn)) + delete_vta_debug_insn (insn); + } + else + for (insn = get_insns (); insn; insn = next) + { + next = NEXT_INSN (insn); if (DEBUG_INSN_P (insn)) - { - if (DEBUG_MARKER_INSN_P (insn)) - { - reemit_marker_as_note (insn); - continue; - } - - tree decl = INSN_VAR_LOCATION_DECL (insn); - if (TREE_CODE (decl) == LABEL_DECL - && DECL_NAME (decl) - && !DECL_RTL_SET_P (decl)) - { - PUT_CODE (insn, NOTE); - NOTE_KIND (insn) = NOTE_INSN_DELETED_DEBUG_LABEL; - NOTE_DELETED_LABEL_NAME (insn) - = IDENTIFIER_POINTER (DECL_NAME (decl)); - SET_DECL_RTL (decl, insn); - CODE_LABEL_NUMBER (insn) = debug_label_num++; - } - else - delete_insn (insn); - } - } + delete_vta_debug_insn (insn); + } } /* Run a fast, BB-local only version of var tracking, to take care of @@ -10322,7 +10338,7 @@ static void vt_debug_insns_local (bool skipped ATTRIBUTE_UNUSED) { /* ??? Just skip it all for now. */ - delete_vta_debug_insns (); + delete_vta_debug_insns (true); } /* Free the data structures needed for variable tracking. */ @@ -10395,7 +10411,7 @@ variable_tracking_main_1 (void) any pseudos at this point. */ || targetm.no_register_allocation) { - delete_vta_debug_insns (); + delete_vta_debug_insns (true); return 0; } @@ -10423,7 +10439,7 @@ variable_tracking_main_1 (void) { vt_finalize (); - delete_vta_debug_insns (); + delete_vta_debug_insns (true); /* This is later restored by our caller. */ flag_var_tracking_assignments = 0; --- gcc/rtl.h.jj 2018-01-03 10:19:55.184533962 +0100 +++ gcc/rtl.h 2018-01-03 15:56:13.089080504 +0100 @@ -4254,6 +4254,7 @@ extern GTY(()) rtx stack_limit_rtx; /* In var-tracking.c */ extern unsigned int variable_tracking_main (void); +extern void delete_vta_debug_insns (bool); /* In stor-layout.c. */ extern void get_mode_bounds (scalar_int_mode, int, --- gcc/final.c.jj 2018-01-03 10:19:54.049533777 +0100 +++ gcc/final.c 2018-01-03 15:56:48.509091487 +0100 @@ -4544,7 +4544,7 @@ rest_of_handle_final (void) /* Turn debug markers into notes if the var-tracking pass has not been invoked. */ if (!flag_var_tracking && MAY_HAVE_DEBUG_MARKER_INSNS) - variable_tracking_main (); + delete_vta_debug_insns (false); assemble_start_function (current_function_decl, fnname); final_start_function (get_insns (), asm_out_file, optimize); --- gcc/testsuite/gcc.dg/pr83645.c.jj 2018-01-03 15:57:37.669106731 +0100 +++ gcc/testsuite/gcc.dg/pr83645.c 2018-01-03 15:57:06.575097090 +0100 @@ -0,0 +1,14 @@ +/* PR debug/83645 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -g -fno-var-tracking" } */ + +int a, b, c[1]; + +void +foo (void) +{ + int i = 0; + b = a; + for (;;) + c[i++] = 7; +}