History

tccgen: fix "Allow declared arrays to be initialized..."

See 355897a9203661b5f54dbb634294a66ceef17ae6

grischka committed 5 years ago

Commit e4f151c1 parent a1d10c81 file · +8 −12Browse files

Unified · Split

tccgen.c+8−12
@@ -8437,18 +8437,6 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 8436 unmodified lines
84378437 macro_ptr = init_str->str;
84388438 next();
84398439
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−
84528440 /* if still unknown size, error */
84538441 size = type_size(type, &align);
84548442 if (size < 0)
@@ -8520,6 +8508,14 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 65 unmodified lines
85208508 /* see if the symbol was already defined */
85218509 sym = sym_find(v);
85228510 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+ }
85238519 patch_storage(sym, ad, type);
85248520 /* we accept several definitions of the same global variable. */
85258521 if (!has_init && sym->c && elfsym(sym)->st_shndx != SHN_UNDEF)

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