tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] typedef bug in tcc-0.9.19 + patch


From: Mauro Persano
Subject: [Tinycc-devel] typedef bug in tcc-0.9.19 + patch
Date: Mon, 7 Jul 2003 09:18:09 -0300 (BRT)

Hi,

There's a small bug in the way tcc-0.9.19 handles typedefs. The 
following (legal) code shows the bug:

    typedef int foo; { int foo; }

Tcc erroneously interprets the second declaration as the empty 
declaration 'int int', when it should be interpreted as a 
declaration of a variable called 'foo' of type 'int'. The
standard says that typedef names can't appear with other type 
specifiers in the same declaration; so, after finding a type 
specifier, the compiler should stop looking for typedef names.

A patch follows below.

Thanks,

    Mauro


diff -ruN tcc-0.9.19/tcc.c tcc-0.9.19-new/tcc.c
--- tcc-0.9.19/tcc.c    Sat May 24 15:30:29 2003
+++ tcc-0.9.19-new/tcc.c        Mon Jul  7 08:09:00 2003
@@ -6204,12 +6204,13 @@
  */
 static int parse_btype(CType *type, AttributeDef *ad)
 {
-    int t, u, type_found;
+    int t, u, type_found, typespec_found;
     Sym *s;
     CType type1;
 
     memset(ad, 0, sizeof(AttributeDef));
     type_found = 0;
+    typespec_found = 0;
     t = 0;
     while(1) {
         switch(tok) {
@@ -6227,6 +6228,7 @@
             if ((t & VT_BTYPE) != 0)
                 error("too many basic types");
             t |= u;
+            typespec_found = 1;
             break;
         case TOK_VOID:
             u = VT_VOID;
@@ -6236,6 +6238,7 @@
             goto basic_type;
         case TOK_INT:
             next();
+            typespec_found = 1;
             break;
         case TOK_LONG:
             next();
@@ -6287,10 +6290,11 @@
             t |= VT_VOLATILE;
             next();
             break;
-        case TOK_REGISTER:
         case TOK_SIGNED1:
         case TOK_SIGNED2:
         case TOK_SIGNED3:
+            typespec_found = 1;
+        case TOK_REGISTER:
         case TOK_AUTO:
         case TOK_RESTRICT1:
         case TOK_RESTRICT2:
@@ -6300,6 +6304,7 @@
         case TOK_UNSIGNED:
             t |= VT_UNSIGNED;
             next();
+            typespec_found = 1;
             break;
 
             /* storage */
@@ -6335,6 +6340,8 @@
             parse_expr_type(&type1);
             goto basic_type2;
         default:
+            if (typespec_found)
+                goto the_end;
             s = sym_find(tok);
             if (!s || !(s->type.t & VT_TYPEDEF))
                 goto the_end;








reply via email to

[Prev in Thread] Current Thread [Next in Thread]