From patchwork Sun Oct 31 06:07:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Martin X-Patchwork-Id: 69698 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 CD86CB70E4 for ; Sun, 31 Oct 2010 18:14:26 +1100 (EST) Received: (qmail 6018 invoked by alias); 31 Oct 2010 07:14:24 -0000 Received: (qmail 6008 invoked by uid 22791); 31 Oct 2010 07:14:22 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (140.186.70.92) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 31 Oct 2010 07:14:18 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PCR7r-0006j7-3P for gcc-patches@gcc.gnu.org; Sun, 31 Oct 2010 02:10:44 -0400 Received: from smtp27.orange.fr ([80.12.242.95]:2479) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PCR7q-0006it-MK for gcc-patches@gcc.gnu.org; Sun, 31 Oct 2010 02:10:43 -0400 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2711.orange.fr (SMTP Server) with ESMTP id EF09E1C000D0 for ; Sun, 31 Oct 2010 07:08:32 +0100 (CET) Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2711.orange.fr (SMTP Server) with ESMTP id DE2BC1C00109 for ; Sun, 31 Oct 2010 07:08:32 +0100 (CET) Received: from [192.168.1.132] (ANice-152-1-6-18.w82-122.abo.wanadoo.fr [82.122.153.18]) by mwinf2711.orange.fr (SMTP Server) with ESMTP id 891DB1C000D0 for ; Sun, 31 Oct 2010 07:08:32 +0100 (CET) X-ME-User-Auth: simon-l.martin Message-ID: <4CCD079D.9040107@users.sourceforge.net> Date: Sun, 31 Oct 2010 07:07:25 +0100 From: Simon Martin User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.12) Gecko/20101027 Thunderbird/3.1.6 MIME-Version: 1.0 To: GCC Patches Subject: [PATCH] Fix PR c/43384: Segmentation fault with invalid K&R-like code X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. 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 Hello all, The cases in that PR are all linked to an invalid initialization of some K&R style function argument: ==== void c_direct(par) void *par = &&lab; {} void foo(p, q) int *p = &q; {} void bar(i) int j = i; {} ==== There are two problems: 1. ICE when initializing the argument with the address of a label 2. ICE when initializing it with error_mark_node The attached patch fixes both cases, by respectively (1) handling invalid references to labels in cases we have 'current_function_decl' but not 'current_function_scope' and (2) skipping erroneous parameters in 'store_parm_decls_oldstyle' I've successfully bootstrapped and tested this on x86_64-apple-darwin-9. Is it OK for trunk? Best regards, Simon 2010-11-01 Simon Martin PR c/43384 * c-decl.c (lookup_label): Labels can only be referenced in a function's scope. (store_parm_decls_oldstyle): Skip erroneous parameters. 2010-11-01 Simon Martin PR c/43384 * gcc.dg/parser-error-3.c: New test. /* PR c/43384 */ /* { dg-do "compile" } */ void c_direct(par) void *par = &&lab; /* { dg-error "is initialized|non-standard|outside of" } */ {} void foo(p, q) int *p = &q; /* { dg-error "initialized|undeclared" } */ {} void bar(i) int j = i; /* { dg-error "initialized|undeclared|no such parameter" } */ {} Index: gcc/c-decl.c =================================================================== --- gcc/c-decl.c (revision 166064) +++ gcc/c-decl.c (working copy) @@ -3013,7 +3013,7 @@ tree label; struct c_label_vars *label_vars; - if (current_function_decl == 0) + if (current_function_scope == 0) { error ("label %qE referenced outside of any function", name); return 0; @@ -7847,6 +7847,9 @@ if (b && B_IN_CURRENT_SCOPE (b)) { decl = b->decl; + /* Skip erroneous parameters. */ + if (decl == error_mark_node) + continue; /* If we got something other than a PARM_DECL it is an error. */ if (TREE_CODE (decl) != PARM_DECL) error_at (DECL_SOURCE_LOCATION (decl),