From patchwork Thu Feb 23 08:56:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 142572 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 2F919B6EE8 for ; Thu, 23 Feb 2012 19:57:07 +1100 (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=1330592228; h=Comment: DomainKey-Signature:Received:Received:Received:Received: Received-SPF:Received:MIME-Version:Received:Received:Date: Message-ID:Subject:From:To:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=7DV9P5BC/0GKijOfwwfhSISNgyU=; b=qUSNGKCJpf6/PbB 6yVBvPT/+bvGIy7PVppHuiLLAub/zI30laIzsTRXK8r+EuZZHH2OUUeS+X6N0TEf FmCKjZSajZilRWziKKTcrm3jw/9Mq2kMAnKC847n2aidX93XT2LNlLZcFq1ZEBch 9KV5kvzNx6Z4k1gFQoomg5VhRRoc= 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-SPF:Authentication-Results:Received:MIME-Version:Received:Received:Date:Message-ID:Subject:From:To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=lVetRZEZSIpAp6fjxLniaDrdC4+DBTMiBTrcsEtmPljNYQX2xIM3Iwubds8qjF HEcXCjEWipssjq0Cr1lpA4B+D7yjguUmbblIGMCDlhyxMkje8DtKsKw360+hGcRd CgEHkUZCo2n458jf1BMly6ehbmr50FEEPQvpre4B9wUG8=; Received: (qmail 5196 invoked by alias); 23 Feb 2012 08:57:01 -0000 Received: (qmail 5186 invoked by uid 22791); 23 Feb 2012 08:56:59 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, TW_ZJ X-Spam-Check-By: sourceware.org Received: from mail-yw0-f47.google.com (HELO mail-yw0-f47.google.com) (209.85.213.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 23 Feb 2012 08:56:44 +0000 Received: by yhfq46 with SMTP id q46so485870yhf.20 for ; Thu, 23 Feb 2012 00:56:44 -0800 (PST) Received-SPF: pass (google.com: domain of ubizjak@gmail.com designates 10.236.46.232 as permitted sender) client-ip=10.236.46.232; Authentication-Results: mr.google.com; spf=pass (google.com: domain of ubizjak@gmail.com designates 10.236.46.232 as permitted sender) smtp.mail=ubizjak@gmail.com; dkim=pass header.i=ubizjak@gmail.com Received: from mr.google.com ([10.236.46.232]) by 10.236.46.232 with SMTP id r68mr649545yhb.80.1329987404024 (num_hops = 1); Thu, 23 Feb 2012 00:56:44 -0800 (PST) MIME-Version: 1.0 Received: by 10.236.46.232 with SMTP id r68mr488603yhb.80.1329987403931; Thu, 23 Feb 2012 00:56:43 -0800 (PST) Received: by 10.146.241.19 with HTTP; Thu, 23 Feb 2012 00:56:43 -0800 (PST) Date: Thu, 23 Feb 2012 09:56:43 +0100 Message-ID: Subject: [PATCH, c]: Fix PR52290, [4.4/4.5/4.6/4.7 Regression] internal compiler error: tree check: expected function_decl, have var_decl in start_function, at c-decl.c:7712 From: Uros Bizjak To: gcc-patches@gcc.gnu.org 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! With invalid code, we can trick grokdeclarator to return VAR_DECL, even when FUNCDEF context is requested. Attached one-liner detects this situation and exits early from start_function. The new error stream looks correct to me, with following invalid testcase we get: $ cat pr52290.c int f()[j] $ ~/gcc-build-fast/gcc/cc1 pr52290.c pr52290.c:3:9: error: ‘j’ undeclared here (not in a function) pr52290.c:3:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ at end of input 2012-02-23 Uros Bizjak * c-decl.c (start_function): Exit early if decl1 is not FUNTION_DECL. testsuite/ChangeLog: 2012-02-23 Uros Bizjak * gcc.dg/noncompile/pr52290.c: New test. Patch was bootstrapped and regression tested on x86_64-pc-linux-gnu. OK for mainline and release branches? Uros. Index: c-decl.c =================================================================== --- c-decl.c (revision 184501) +++ c-decl.c (working copy) @@ -7702,7 +7702,8 @@ start_function (struct c_declspecs *declspecs, str /* If the declarator is not suitable for a function definition, cause a syntax error. */ - if (decl1 == 0) + if (decl1 == 0 + || TREE_CODE (decl1) != FUNCTION_DECL) return 0; loc = DECL_SOURCE_LOCATION (decl1); Index: testsuite/gcc.dg/noncompile/pr52290.c =================================================================== --- testsuite/gcc.dg/noncompile/pr52290.c (revision 0) +++ testsuite/gcc.dg/noncompile/pr52290.c (revision 0) @@ -0,0 +1,3 @@ +/* { dg-error "undeclared here" "" { target *-*-* } 3 } */ +/* { dg-error "expected" "" { target *-*-* } 3 } */ +int f()[j]