Fix type parsing
the check on incomplete struct/union/enum types was too early, disallowing mixed specifiers and qualifiers. Simply rely on the size (->c) field for that. See testcases.
This commit is contained in:
		
							parent
							
								
									aa1ed616eb
								
							
						
					
					
						commit
						f85db99ff0
					
				
					 4 changed files with 19 additions and 7 deletions
				
			
		
							
								
								
									
										15
									
								
								tccgen.c
									
										
									
									
									
								
							
							
						
						
									
										15
									
								
								tccgen.c
									
										
									
									
									
								
							|  | @ -2200,7 +2200,7 @@ ST_FUNC int type_size(CType *type, int *a) | |||
|         *a = 8; | ||||
| #endif | ||||
|         return 8; | ||||
|     } else if (bt == VT_INT || bt == VT_ENUM || bt == VT_FLOAT) { | ||||
|     } else if (bt == VT_INT || bt == VT_FLOAT) { | ||||
|         *a = 4; | ||||
|         return 4; | ||||
|     } else if (bt == VT_SHORT) { | ||||
|  | @ -2209,6 +2209,10 @@ ST_FUNC int type_size(CType *type, int *a) | |||
|     } else if (bt == VT_QLONG || bt == VT_QFLOAT) { | ||||
|         *a = 8; | ||||
|         return 16; | ||||
|     } else if (bt == VT_ENUM) { | ||||
| 	*a = 4; | ||||
| 	/* Enums might be incomplete, so don't just return '4' here.  */ | ||||
| 	return type->ref->c; | ||||
|     } else { | ||||
|         /* char, void, function, _Bool */ | ||||
|         *a = 1; | ||||
|  | @ -2902,7 +2906,7 @@ static void parse_attribute(AttributeDef *ad) | |||
| } | ||||
| 
 | ||||
| /* enum/struct/union declaration. u is either VT_ENUM or VT_STRUCT */ | ||||
| static void struct_decl(CType *type, int u, int tdef) | ||||
| static void struct_decl(CType *type, int u) | ||||
| { | ||||
|     int a, v, size, align, maxalign, c, offset, flexible; | ||||
|     int bit_size, bit_pos, bsize, bt, lbit_pos, prevbt; | ||||
|  | @ -2923,8 +2927,7 @@ static void struct_decl(CType *type, int u, int tdef) | |||
|             if (s->type.t != a) | ||||
|                 tcc_error("invalid type"); | ||||
|             goto do_decl; | ||||
|         } else if (tok >= TOK_IDENT && !tdef) | ||||
|             tcc_error("unknown struct/union/enum"); | ||||
|         } | ||||
|     } else { | ||||
|         v = anon_sym++; | ||||
|     } | ||||
|  | @ -3229,14 +3232,14 @@ static int parse_btype(CType *type, AttributeDef *ad) | |||
|             } | ||||
|             break; | ||||
|         case TOK_ENUM: | ||||
|             struct_decl(&type1, VT_ENUM, t & (VT_TYPEDEF | VT_EXTERN)); | ||||
|             struct_decl(&type1, VT_ENUM); | ||||
|         basic_type2: | ||||
|             u = type1.t; | ||||
|             type->ref = type1.ref; | ||||
|             goto basic_type1; | ||||
|         case TOK_STRUCT: | ||||
|         case TOK_UNION: | ||||
|             struct_decl(&type1, VT_STRUCT, t & (VT_TYPEDEF | VT_EXTERN)); | ||||
|             struct_decl(&type1, VT_STRUCT); | ||||
|             goto basic_type2; | ||||
| 
 | ||||
|             /* type modifiers */ | ||||
|  |  | |||
|  | @ -1 +1 @@ | |||
| 61_undefined_enum.c:1: error: unknown struct/union/enum | ||||
| 61_undefined_enum.c:1: error: unknown type size | ||||
|  |  | |||
							
								
								
									
										9
									
								
								tests/tests2/81_types.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								tests/tests2/81_types.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,9 @@ | |||
| /* The following are all valid decls, even though some subtypes
 | ||||
|    are incomplete.  */ | ||||
| enum E *e; | ||||
| const enum E *e1; | ||||
| enum E const *e2; | ||||
| struct S *s; | ||||
| const struct S *s1; | ||||
| struct S const *s2; | ||||
| int main () { return 0; } | ||||
							
								
								
									
										0
									
								
								tests/tests2/81_types.expect
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								tests/tests2/81_types.expect
									
										
									
									
									
										Normal file
									
								
							
		Loading…
	
	Add table
		
		Reference in a new issue