See 355897a9203661b5f54dbb634294a66ceef17ae6
Unified · Split
| @@ -8437,18 +8437,6 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 8436 unmodified lines | |||
| 8437 | macro_ptr = init_str->str; | 8437 | macro_ptr = init_str->str; |
| 8438 | next(); | 8438 | next(); |
| 8439 | 8439 | ||
| 8440 | sym = sym_find(v); | ||
| 8441 | /* If the base type itself was an array type of unspecified size | ||
| 8442 | (like in 'int arr[] = {1};') when the array was already declared | ||
| 8443 | (like in 'extern arr[10];') we want to use the originally declared | ||
| 8444 | size and not deduce it from the initializer */ | ||
| 8445 | if(sym && sym->type.ref->c > 0) { | ||
| 8446 | if(type->ref->c > sym->type.ref->c) | ||
| 8447 | tcc_error("incompatible types for redefinition of '%s'", | ||
| 8448 | get_tok_str(sym->v, NULL)); | ||
| 8449 | type->ref->c = sym->type.ref->c; | ||
| 8450 | } | ||
| 8451 | |||
| 8452 | /* if still unknown size, error */ | 8440 | /* if still unknown size, error */ |
| 8453 | size = type_size(type, &align); | 8441 | size = type_size(type, &align); |
| 8454 | if (size < 0) | 8442 | if (size < 0) |
| @@ -8520,6 +8508,14 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 65 unmodified lines | |||
| 8520 | /* see if the symbol was already defined */ | 8508 | /* see if the symbol was already defined */ |
| 8521 | sym = sym_find(v); | 8509 | sym = sym_find(v); |
| 8522 | if (sym) { | 8510 | if (sym) { |
| 8511 | if (p.flex_array_ref && (sym->type.t & type->t & VT_ARRAY) | ||
| 8512 | && sym->type.ref->c > type->ref->c) { | ||
| 8513 | /* flex array was already declared with explicit size | ||
| 8514 | extern int arr[10]; | ||
| 8515 | int arr[] = { 1,2,3 }; */ | ||
| 8516 | type->ref->c = sym->type.ref->c; | ||
| 8517 | size = type_size(type, &align); | ||
| 8518 | } | ||
| 8523 | patch_storage(sym, ad, type); | 8519 | patch_storage(sym, ad, type); |
| 8524 | /* we accept several definitions of the same global variable. */ | 8520 | /* we accept several definitions of the same global variable. */ |
| 8525 | if (!has_init && sym->c && elfsym(sym)->st_shndx != SHN_UNDEF) | 8521 | if (!has_init && sym->c && elfsym(sym)->st_shndx != SHN_UNDEF) |