History

Make parse_btype only accept one basic type

This makes int char c; and struct {} int c; generate an error. Thanks Mobi Phil for reporting.

Thomas Preud'homme committed 12 years ago

Commit b68499e1 parent ec1c8301 file · +15 −8Browse files

Unified · Split

tccgen.c+15−8
@@ -2988,19 +2988,25 @@ static void struct_decl(CType *type, int u, int tdef) · 2987 unmodified lines
29882988 }
29892989 }
29902990
2991+/* return 1 if basic type is a type size (short, long, long long) */
2992+int is_btype_size (int bt)
2993+{
2994+ return bt == VT_SHORT || bt == VT_LONG || bt == VT_LLONG;
2995+}
2996+
29912997 /* return 0 if no type declaration. otherwise, return the basic type
29922998 and skip it.
29932999 */
29943000 static int parse_btype(CType *type, AttributeDef *ad)
29953001 {
2996− int t, u, type_found, typespec_found, typedef_found;
3002+ int t, u, bt_size, complete, type_found, typespec_found;
29973003 Sym *s;
29983004 CType type1;
29993005
30003006 memset(ad, 0, sizeof(AttributeDef));
3007+ complete = 0;
30013008 type_found = 0;
30023009 typespec_found = 0;
3003− typedef_found = 0;
30043010 t = 0;
30053011 while(1) {
30063012 switch(tok) {
@@ -3015,9 +3021,12 @@ static int parse_btype(CType *type, AttributeDef *ad) · 8 unmodified lines
30153021 basic_type:
30163022 next();
30173023 basic_type1:
3018− if ((t & VT_BTYPE) != 0)
3024+ if (complete)
30193025 tcc_error("too many basic types");
30203026 t |= u;
3027+ bt_size = is_btype_size (u & VT_BTYPE);
3028+ if (u == VT_INT || (!bt_size && !(t & VT_TYPEDEF)))
3029+ complete = 1;
30213030 typespec_found = 1;
30223031 break;
30233032 case TOK_VOID:
@@ -3027,9 +3036,8 @@ static int parse_btype(CType *type, AttributeDef *ad) · 3 unmodified lines
30273036 u = VT_SHORT;
30283037 goto basic_type;
30293038 case TOK_INT:
3030− next();
3031− typespec_found = 1;
3032− break;
3039+ u = VT_INT;
3040+ goto basic_type;
30333041 case TOK_LONG:
30343042 next();
30353043 if ((t & VT_BTYPE) == VT_DOUBLE) {
@@ -3149,12 +3157,11 @@ static int parse_btype(CType *type, AttributeDef *ad) · 113 unmodified lines
31493157 type1.t &= ~(VT_STORAGE&~VT_TYPEDEF);
31503158 goto basic_type2;
31513159 default:
3152− if (typespec_found || typedef_found)
3160+ if (typespec_found)
31533161 goto the_end;
31543162 s = sym_find(tok);
31553163 if (!s || !(s->type.t & VT_TYPEDEF))
31563164 goto the_end;
3157− typedef_found = 1;
31583165 t |= (s->type.t & ~VT_TYPEDEF);
31593166 type->ref = s->type.ref;
31603167 if (s->r) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t