This for example suppresses string constants such as with int main() { return sizeof "foo"; } Actually, setting nocode_wanted = 1; in libtcc.c for the initial global level seemed wrong, since obviously "nocode_wanted" means code as any side effects, also such as string constants. This reverts a part of 2de1b2d14cc920e2c698ff0086f5558c2da7f569 (documented as "Some in-between fixes" in Changelog)
Unified · Split
| @@ -778,7 +778,6 @@ static int tcc_compile(TCCState *s1) · 777 unmodified lines | ||
| 778 | 778 | #endif |
| 779 | 779 | |
| 780 | 780 | define_start = define_stack; |
| 781 | − nocode_wanted = 1; | |
| 782 | 781 | |
| 783 | 782 | if (setjmp(s1->error_jmp_buf) == 0) { |
| 784 | 783 | s1->nb_errors = 0; |
| @@ -5528,9 +5528,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 5527 unmodified lines | ||
| 5528 | 5528 | literals). It also simplifies local |
| 5529 | 5529 | initializers handling */ |
| 5530 | 5530 | tok_str_new(&init_str); |
| 5531 | − if (size < 0 || (flexible_array && has_init)) { | |
| 5532 | − if (!has_init) | |
| 5533 | − tcc_error("unknown type size"); | |
| 5531 | + if ((size < 0 || flexible_array) && has_init) { | |
| 5534 | 5532 | /* get all init string */ |
| 5535 | 5533 | if (has_init == 2) { |
| 5536 | 5534 | /* only get strings */ |
| @@ -5569,11 +5567,19 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 32 unmodified lines | ||
| 5569 | 5567 | macro_ptr = init_str.str; |
| 5570 | 5568 | next(); |
| 5571 | 5569 | |
| 5572 | − /* if still unknown size, error */ | |
| 5573 | 5570 | size = type_size(type, &align); |
| 5574 | − if (size < 0) | |
| 5575 | − tcc_error("unknown type size"); | |
| 5576 | 5571 | } |
| 5572 | + | |
| 5573 | + /* if still unknown size, error */ | |
| 5574 | + if (size < 0) | |
| 5575 | + tcc_error("unknown type size"); | |
| 5576 | + | |
| 5577 | + if (nocode_wanted) { | |
| 5578 | + //tcc_warning("nocode_wanted set for decl_initializer_alloc"); | |
| 5579 | + vset(type, r, 0); | |
| 5580 | + goto no_alloc; | |
| 5581 | + } | |
| 5582 | + | |
| 5577 | 5583 | if (flexible_array) |
| 5578 | 5584 | size += flexible_array->type.ref->c * pointed_size(&flexible_array->type); |
| 5579 | 5585 | /* take into account specified alignment if bigger */ |
| @@ -5720,17 +5726,17 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 140 unmodified lines | ||
| 5720 | 5726 | } |
| 5721 | 5727 | if (has_init || (type->t & VT_VLA)) { |
| 5722 | 5728 | decl_initializer(type, sec, addr, 1, 0); |
| 5723 | − /* restore parse state if needed */ | |
| 5724 | − if (init_str.str) { | |
| 5725 | − tok_str_free(init_str.str); | |
| 5726 | − restore_parse_state(&saved_parse_state); | |
| 5727 | − } | |
| 5728 | 5729 | /* patch flexible array member size back to -1, */ |
| 5729 | 5730 | /* for possible subsequent similar declarations */ |
| 5730 | 5731 | if (flexible_array) |
| 5731 | 5732 | flexible_array->type.ref->c = -1; |
| 5732 | 5733 | } |
| 5733 | − no_alloc: ; | |
| 5734 | +no_alloc: | |
| 5735 | + /* restore parse state if needed */ | |
| 5736 | + if (init_str.str) { | |
| 5737 | + tok_str_free(init_str.str); | |
| 5738 | + restore_parse_state(&saved_parse_state); | |
| 5739 | + } | |
| 5734 | 5740 | } |
| 5735 | 5741 | |
| 5736 | 5742 | static void put_func_debug(Sym *sym) |
| @@ -5802,8 +5808,6 @@ static void func_decl_list(Sym *func_sym) · 65 unmodified lines | ||
| 5802 | 5808 | 'cur_text_section' */ |
| 5803 | 5809 | static void gen_function(Sym *sym) |
| 5804 | 5810 | { |
| 5805 | − int saved_nocode_wanted = nocode_wanted; | |
| 5806 | − nocode_wanted = 0; | |
| 5807 | 5811 | ind = cur_text_section->data_offset; |
| 5808 | 5812 | /* NOTE: we patch the symbol size later */ |
| 5809 | 5813 | put_extern_sym(sym, cur_text_section, ind, 0); |
| @@ -5859,7 +5863,6 @@ static void gen_function(Sym *sym) · 49 unmodified lines | ||
| 5859 | 5863 | func_vt.t = VT_VOID; /* for safety */ |
| 5860 | 5864 | func_var = 0; /* for safety */ |
| 5861 | 5865 | ind = 0; /* for safety */ |
| 5862 | − nocode_wanted = saved_nocode_wanted; | |
| 5863 | 5866 | } |
| 5864 | 5867 | |
| 5865 | 5868 | ST_FUNC void gen_inline_functions(void) |