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
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)

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