From patchwork Wed Nov 16 17:02:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Matz X-Patchwork-Id: 126005 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]) by ozlabs.org (Postfix) with SMTP id 957CEB70ED for ; Thu, 17 Nov 2011 04:03:12 +1100 (EST) Received: (qmail 6620 invoked by alias); 16 Nov 2011 17:03:06 -0000 Received: (qmail 6599 invoked by uid 22791); 16 Nov 2011 17:03:04 -0000 X-SWARE-Spam-Status: No, hits=-3.6 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 16 Nov 2011 17:02:50 +0000 Received: from relay1.suse.de (nat.nue.novell.com [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id B9B158C061 for ; Wed, 16 Nov 2011 18:02:48 +0100 (CET) Date: Wed, 16 Nov 2011 18:02:48 +0100 (CET) From: Michael Matz To: gcc-patches@gcc.gnu.org Subject: Fix PRs 50644,50741, segfaults in set_is_used Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes 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 Hi, this patch fixes both problems by using the same condition as add_referenced_var uses to guard walking into initializers. I've considered some other solutions but the real nice one (merging local_decls and referenced_vars, and not using annotations for the used flag) doesn't seem appropriate for stage 3, and all the other ones would just look similar. I've deviated from richis proposed patch in 50741 in that I guard only walking into initializers of non-local vars, but still add those vars itself (so the invariant that all variables that are somehow mentioned in any instruction are in referenced_vars still holds). This doesn't fix the fortran PR50640 (select_type_12 segfault). This testcase shows two problems, one is fixed by this patch, the other remains. As the audit trail explains the fortran frontend really should present different code. Regstrapping for x86_64-linux in progress (all languages+Ada). Okay if that passes? Ciao, Michael. ---------------- PR middle-end/50644 PR middle-end/50741 * tree-ssa-live.c (mark_all_vars_used_1): Recurse only for decls of current function. (remove_unused_locals): Ditto. testsuite/ PR middle-end/50644 PR middle-end/50741 * g++.dg/tree-ssa/pr50741.C: New. Index: tree-ssa-live.c =================================================================== --- tree-ssa-live.c (revision 181172) +++ tree-ssa-live.c (working copy) @@ -374,7 +374,8 @@ mark_all_vars_used_1 (tree *tp, int *wal eliminated as unused. */ if (TREE_CODE (t) == VAR_DECL) { - if (data != NULL && bitmap_clear_bit ((bitmap) data, DECL_UID (t))) + if (data != NULL && bitmap_clear_bit ((bitmap) data, DECL_UID (t)) + && DECL_CONTEXT (t) == current_function_decl) mark_all_vars_used (&DECL_INITIAL (t), data); set_is_used (t); } @@ -836,7 +837,8 @@ remove_unused_locals (void) if (TREE_CODE (var) == VAR_DECL && is_global_var (var) && var_ann (var) != NULL - && is_used_p (var)) + && is_used_p (var) + && DECL_CONTEXT (var) == current_function_decl) mark_all_vars_used (&DECL_INITIAL (var), global_unused_vars); num = VEC_length (tree, cfun->local_decls); Index: testsuite/g++.dg/tree-ssa/pr50741.C =================================================================== --- testsuite/g++.dg/tree-ssa/pr50741.C (revision 0) +++ testsuite/g++.dg/tree-ssa/pr50741.C (revision 0) @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -g" } */ +/* PR middle-end/50741 */ + +struct PublishLo +{ + const char *functionName; + ~PublishLo(); +}; +struct A { A(); }; +A::A() +{ + static PublishLo _rL_53 = {__FUNCTION__}; +}