diff mbox

detect unknown type names in declaration

Message ID 4CDEBA51.3020207@gnu.org
State New
Headers show

Commit Message

Paolo Bonzini Nov. 13, 2010, 4:18 p.m. UTC
On 11/13/2010 03:15 PM, H.J. Lu wrote:
> On Sat, Oct 30, 2010 at 6:24 AM, Paolo Bonzini<bonzini@gnu.org>  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<bonzini@gnu.org>
>>
>>         * 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  <bonzini@gnu.org>

        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.

Comments

H.J. Lu Nov. 13, 2010, 4:25 p.m. UTC | #1
On Sat, Nov 13, 2010 at 8:18 AM, Paolo Bonzini <bonzini@gnu.org> wrote:
> On 11/13/2010 03:15 PM, H.J. Lu wrote:
>>
>> On Sat, Oct 30, 2010 at 6:24 AM, Paolo Bonzini<bonzini@gnu.org>  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<bonzini@gnu.org>
>>>
>>>        * 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.

There is one ICE:

FAIL: gcc.dg/pr14963.c (internal compiler error)
FAIL: gcc.dg/pr14963.c (test for excess errors)

It looks like a real bug.
Paolo Bonzini Nov. 13, 2010, 4:51 p.m. UTC | #2
On 11/13/2010 05:25 PM, H.J. Lu wrote:
> There is one ICE:
>
> FAIL: gcc.dg/pr14963.c (internal compiler error)
> FAIL: gcc.dg/pr14963.c (test for excess errors)
>
> It looks like a real bug.

It is PR45062, it's just exposed by this patch because the problematic 
statement is parsed instead of skipped.  So the ICE is "correct", it's 
an improvement in coverage.

Paolo
diff mbox

Patch

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" } */