From patchwork Wed Jun 20 19:32:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meador Inge X-Patchwork-Id: 166134 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 E62F2B6FBD for ; Thu, 21 Jun 2012 05:32:46 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1340825567; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:CC:Subject:Date:Message-ID:MIME-Version: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=C2hh078 lv7MGq5j42Vjtslmsttk=; b=SiKp1pdfLLVsF0maw/OwQ3v0Lp4bihlGTvxGBPb n+PRKVtMBNuY3CF6AIVXyOgdMiGnik2mOIclpsrb1378fUdmnNk0mcSb7tG12tQC O0NyFBwRbXE5MIOHGEyu9BECnuISNBBbWruLFJTz4X5z5gGa6dMIxK3xW8W1iUMT lxuU= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=cEBE3frlsKvv/YGpgxQAcZ3fYHYb7dnBIgtmtKwcpMtt0KM124aZ53k16mOhIp rBgNDd8bqhdrEL47buCaKsyD1G1kJRXAIVW2o7tGWgt0tpWrlF2yboFPEyemFQZx 7cQi7OxQRScSzUeSkTLtGG79NDKlpDp3vagTZE61uMCY8=; Received: (qmail 1558 invoked by alias); 20 Jun 2012 19:32:43 -0000 Received: (qmail 1549 invoked by uid 22791); 20 Jun 2012 19:32:42 -0000 X-SWARE-Spam-Status: No, hits=-3.7 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, TW_TM X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 20 Jun 2012 19:32:29 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1ShQdg-0004mv-3i from meador_inge@mentor.com for gcc-patches@gcc.gnu.org; Wed, 20 Jun 2012 12:32:28 -0700 Received: from SVR-ORW-FEM-03.mgc.mentorg.com ([147.34.97.39]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Wed, 20 Jun 2012 12:31:47 -0700 Received: from dhalsim.gateway.2wire.net (147.34.91.1) by svr-orw-fem-03.mgc.mentorg.com (147.34.97.39) with Microsoft SMTP Server id 14.1.289.1; Wed, 20 Jun 2012 12:32:27 -0700 From: Meador Inge To: CC: Subject: [PATCH] PR c/53702: Fix -Wunused-local-typedefs with nested functions Date: Wed, 20 Jun 2012 14:32:25 -0500 Message-ID: <1340220746-27813-1-git-send-email-meadori@codesourcery.com> 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, A few weeks ago I submitted a fix for a garbage collection issue I ran into involving -Wunused-local-typedefs [1]. The analysis for that patch still stands, but unfortunately the patch is wrong. The problem is that the allocation reuse can't be removed otherwise the information about local typedefs for a parent function is lost after a nested function is parsed. I obviously missed that distinction the first time. This patch restores the previous behavior and just clears the 'x_cur_stmt_list' field to avoid the GC issue. The patch was tested by building mips-linux-gnu (to verify that the GC crash that I originally encountered is still fixed) and by bootstrapping and running the full test suite for i686-pc-linux-gnu. OK? P.S. If it is OK, then can someone commit for me (I don't have write access)? [1] http://gcc.gnu.org/ml/gcc-patches/2012-05/msg01936.html gcc/ 2012-06-20 Meador Inge PR c/53702 * c-decl.c (c_push_function_context): Restore the behavior to reuse the language function allocated for -Wunused-local-typedefs. (c_pop_function_context): If necessary, clear the language function created in c_push_function_context. Always clear out the x_cur_stmt_list field of the restored language function. gcc/testsuite/ 2012-06-20 Meador Inge PR c/53702 * gcc.dg/Wunused-local-typedefs.c: New testcase. Index: gcc/testsuite/gcc.dg/Wunused-local-typedefs.c =================================================================== --- gcc/testsuite/gcc.dg/Wunused-local-typedefs.c (revision 0) +++ gcc/testsuite/gcc.dg/Wunused-local-typedefs.c (revision 0) @@ -0,0 +1,36 @@ +/* Origin PR c/53702 + { dg-options "-Wunused-local-typedefs" } + { dg-do compile } +*/ + +/* Only test nested functions for C. More tests that work for C and C++ + can be found in c-c++-common. +*/ + +void +test0 () +{ + typedef int foo; /* { dg-warning "locally defined but not used" } */ + void f () + { + } +} + +void +test1 () +{ + void f () + { + typedef int foo; /* { dg-warning "locally defined but not used" } */ + } +} + + +void +test2 () +{ + void f () + { + } + typedef int foo; /* { dg-warning "locally defined but not used" } */ +} Index: gcc/c-decl.c =================================================================== --- gcc/c-decl.c (revision 188841) +++ gcc/c-decl.c (working copy) @@ -8579,9 +8579,11 @@ check_for_loop_decls (location_t loc, bo void c_push_function_context (void) { - struct language_function *p; - p = ggc_alloc_language_function (); - cfun->language = p; + struct language_function *p = cfun->language; + /* cfun->language might have been already allocated by the use of + -Wunused-local-typedefs. In that case, just re-use it. */ + if (p == NULL) + cfun->language = p = ggc_alloc_cleared_language_function (); p->base.x_stmt_tree = c_stmt_tree; c_stmt_tree.x_cur_stmt_list @@ -8607,7 +8609,12 @@ c_pop_function_context (void) pop_function_context (); p = cfun->language; - cfun->language = NULL; + + /* When -Wunused-local-typedefs is in effect, cfun->languages is + used to store data throughout the life time of the current cfun, + So don't deallocate it. */ + if (!warn_unused_local_typedefs) + cfun->language = NULL; if (DECL_STRUCT_FUNCTION (current_function_decl) == 0 && DECL_SAVED_TREE (current_function_decl) == NULL_TREE) @@ -8620,6 +8627,7 @@ c_pop_function_context (void) } c_stmt_tree = p->base.x_stmt_tree; + p->base.x_stmt_tree.x_cur_stmt_list = NULL; c_break_label = p->x_break_label; c_cont_label = p->x_cont_label; c_switch_stack = p->x_switch_stack;