From patchwork Sat Nov 13 16:18:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 71055 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 380F8B7120 for ; Sun, 14 Nov 2010 03:19:13 +1100 (EST) Received: (qmail 22949 invoked by alias); 13 Nov 2010 16:19:10 -0000 Received: (qmail 22934 invoked by uid 22791); 13 Nov 2010 16:19:07 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mail-fx0-f47.google.com (HELO mail-fx0-f47.google.com) (209.85.161.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 13 Nov 2010 16:18:30 +0000 Received: by fxm11 with SMTP id 11so2557804fxm.20 for ; Sat, 13 Nov 2010 08:18:28 -0800 (PST) Received: by 10.223.54.132 with SMTP id q4mr2793991fag.117.1289665108178; Sat, 13 Nov 2010 08:18:28 -0800 (PST) Received: from yakj.usersys.redhat.com (s209p8.home.99maxprogres.cz [85.93.118.17]) by mx.google.com with ESMTPS id d20sm365609fav.38.2010.11.13.08.18.26 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 13 Nov 2010 08:18:27 -0800 (PST) Message-ID: <4CDEBA51.3020207@gnu.org> Date: Sat, 13 Nov 2010 17:18:25 +0100 From: Paolo Bonzini User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.12) Gecko/20101027 Fedora/3.1.6-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.6 MIME-Version: 1.0 To: "H.J. Lu" CC: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] detect unknown type names in declaration References: <1288445090-8881-1-git-send-email-bonzini@gnu.org> In-Reply-To: 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 On 11/13/2010 03:15 PM, H.J. Lu wrote: > On Sat, Oct 30, 2010 at 6:24 AM, Paolo Bonzini wrote: >> This patch improves GCC error detection so that some cases of >> declarations with unknown type names are detected. This also >> allows GCC to do better on cascading errors, because the variables >> that are declared enter the symbol table. >> >> Bootstrapped/regtested x86_64-pc-linux-gnu, ok? >> >> 2010-10-30 Paolo Bonzini >> >> * c-parser.c (c_parser_next_token_starts_declaration): Rename to... >> (c_parser_next_tokens_start_declaration): ... this. Handle 2nd >> token lookahead. >> (c_parser_compound_statement_nostart, c_parser_label, >> c_parser_for_statement, c_parser_omp_for_loop): Adjust calls. >> (c_parser_declaration_or_fndef): Detect the case now matched by >> c_parser_next_tokens_start_declaration, give error and correct it. >> > > This caused: > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46462 I'm committing the attached testsuite patch, which simply adjust the errors (they are now more precise). I'll post shortly a small adjustment to the C parser to unbreak Objective-C foreach and improve error recovery further. Paolo 2010-11-13 Paolo Bonzini PR c/46462 * gcc.dg/gomp/pr34607.c: Adjust errors for unknown typenames. * gcc.dg/pr35746.c: Likewise. * gcc.dg/cpp/direct2.c: Likewise. * gcc.dg/cpp/direct2s.c: Likewise. * gcc.dg/noncompile/920923-1.c: Likewise. * gcc.dg/dfp/constants-c99.c: Add -Wno-overflow. Index: testsuite/gcc.dg/gomp/pr34607.c =================================================================== --- testsuite/gcc.dg/gomp/pr34607.c (revision 166700) +++ testsuite/gcc.dg/gomp/pr34607.c (working copy) @@ -1,7 +1,6 @@ /* PR c++/34607 */ /* { dg-do compile } */ /* { dg-options "-fopenmp -std=gnu99" } */ -/* { dg-message "undeclared identifier is reported only once" "reminder" { target *-*-* } 0 } */ void foo () { @@ -9,10 +8,10 @@ foo () for (int i =; i < 2; ++i) /* { dg-error "expected expression before" } */ ; #pragma omp for - for (T i = 54; i < 56; i++) /* { dg-error "expected iteration declaration" } */ + for (T i = 54; i < 56; i++) /* { dg-error "unknown type name" } */ ; - T j; /* { dg-error "undeclared|for each function|expected" } */ + T j; /* { dg-error "unknown type name" } */ #pragma omp for - for (j = 1; j < 3; j++) /* { dg-error "undeclared" } */ + for (j = 1; j < 3; j++) ; } Index: testsuite/gcc.dg/pr35746.c =================================================================== --- testsuite/gcc.dg/pr35746.c (revision 166700) +++ testsuite/gcc.dg/pr35746.c (working copy) @@ -6,8 +6,7 @@ int foo(int i); void bar() { __complex__ int i; - X j; /* { dg-error "undeclared|expected" } */ - /* { dg-message "undeclared identifier is reported only once" "reminder" { target *-*-* } 9 } */ - if (i = foo(j)) /* { dg-error "undeclared" } */ + X j; /* { dg-error "unknown" } */ + if (i = foo(j)) ; } Index: testsuite/gcc.dg/cpp/direct2.c =================================================================== --- testsuite/gcc.dg/cpp/direct2.c (revision 166700) +++ testsuite/gcc.dg/cpp/direct2.c (working copy) @@ -20,13 +20,13 @@ int resync_parser_2; void g1 () { -HASH define X 1 /* { dg-error "stray|undeclared|parse|syntax|expected|for each" "# from macro" } */ +HASH define X 1 /* { dg-error "stray|unknown|expected" "# from macro" } */ int resync_parser_3; } void g2 () { -HASHDEFINE Y 1 /* { dg-error "stray|undeclared|parse|syntax|expected|for each" "#define from macro" } */ +HASHDEFINE Y 1 /* { dg-error "stray|unknown|expected" "#define from macro" } */ int resync_parser_4; } Index: testsuite/gcc.dg/cpp/direct2s.c =================================================================== --- testsuite/gcc.dg/cpp/direct2s.c (revision 166700) +++ testsuite/gcc.dg/cpp/direct2s.c (working copy) @@ -22,13 +22,13 @@ int resync_parser_2; void g1 () { -HASH define X 1 /* { dg-error "stray|undeclared|parse|syntax|expected|for each" "# from macro" } */ +HASH define X 1 /* { dg-error "stray|unknown|expected" "# from macro" } */ int resync_parser_3; } void g2 () { -HASHDEFINE Y 1 /* { dg-error "stray|undeclared|parse|syntax|expected|for each" "#define from macro" } */ +HASHDEFINE Y 1 /* { dg-error "stray|unknown|expected" "#define from macro" } */ int resync_parser_4; } Index: testsuite/gcc.dg/dfp/constants-c99.c =================================================================== --- testsuite/gcc.dg/dfp/constants-c99.c (revision 166700) +++ testsuite/gcc.dg/dfp/constants-c99.c (working copy) @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-std=c99" } */ +/* { dg-options "-std=c99 -Wno-overflow" } */ /* N1150 6: Constants. C99 6.4.4.2: Floating constants. */ Index: testsuite/gcc.dg/noncompile/920923-1.c =================================================================== --- testsuite/gcc.dg/noncompile/920923-1.c (revision 166700) +++ testsuite/gcc.dg/noncompile/920923-1.c (working copy) @@ -1,3 +1,4 @@ +/* { dg-message "undeclared identifier is reported only once" "reminder" { target *-*-* } 0 } */ typedef BYTE unsigned char; /* { dg-error "expected" } */ typedef int item_n; typedef int perm_set; @@ -5,7 +6,7 @@ struct PENT { caddr_t v_addr; };/* { dg- typedef struct PENT prec; typedef struct PENT *prec_t; prec_t mem_hash; -BYTE *mem_base; /* { dg-error "expected" } */ +BYTE *mem_base; /* { dg-error "unknown type name" } */ struct PTE { BYTE *p_page; /* { dg-error "expected" } */ perm_set p_perms; @@ -24,9 +25,9 @@ int pcount=0; void mmu_walk_find(va) -caddr_t va; /* { dg-error "expected" } */ +caddr_t va; /* { dg-error "unknown type name" } */ { - BYTE *page_addr; /* { dg-error "undeclared|for each function" } */ + BYTE *page_addr; /* { dg-error "unknown type name" } */ if (mmu_base[Level1(va)]->valid==0x0) { /* { dg-error "undeclared" } */ l1_base = mmu_base[Level1(va)]->(u.p_tablep) = p_alloc(); /* { dg-error "expected|undeclared" } */ mmu_base[Level1(va)]->valid = 0x3; @@ -52,7 +53,7 @@ caddr_t va; /* { dg-error "expected" } void * a_translate(va_op, v_addr) int va_op; -caddr_t v_addr; /* { dg-error "expected" } */ +caddr_t v_addr; /* { dg-error "unknown type name" } */ { register prec_t bucket; register caddr_t p_addr; /* { dg-error "expected|undeclared" } */