History

tccgen: nocode_wanted: do not output constants

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)

grischka committed 12 years ago

Commit 14745bd1 parent 12f43952 files · +18 −16Browse files

Unified · Split

2 files
  1. libtcc.c +0 −1
  2. tccgen.c +18 −15
libtcc.c+0−1
@@ -778,7 +778,6 @@ static int tcc_compile(TCCState *s1) · 777 unmodified lines
778#endif778#endif
779 779
780 define_start = define_stack;780 define_start = define_stack;
781 nocode_wanted = 1;
782 781
783 if (setjmp(s1->error_jmp_buf) == 0) {782 if (setjmp(s1->error_jmp_buf) == 0) {
784 s1->nb_errors = 0;783 s1->nb_errors = 0;
tccgen.c+18−15
@@ -5528,9 +5528,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 5527 unmodified lines
5528 literals). It also simplifies local5528 literals). It also simplifies local
5529 initializers handling */5529 initializers handling */
5530 tok_str_new(&init_str);5530 tok_str_new(&init_str);
5531 if (size < 0 || (flexible_array && has_init)) {5531 if ((size < 0 || flexible_array) && has_init) {
5532 if (!has_init)
5533 tcc_error("unknown type size");
5534 /* get all init string */5532 /* get all init string */
5535 if (has_init == 2) {5533 if (has_init == 2) {
5536 /* only get strings */5534 /* only get strings */
@@ -5569,11 +5567,19 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 32 unmodified lines
5569 macro_ptr = init_str.str;5567 macro_ptr = init_str.str;
5570 next();5568 next();
5571 5569
5572 /* if still unknown size, error */
5573 size = type_size(type, &align);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 if (flexible_array)5583 if (flexible_array)
5578 size += flexible_array->type.ref->c * pointed_size(&flexible_array->type);5584 size += flexible_array->type.ref->c * pointed_size(&flexible_array->type);
5579 /* take into account specified alignment if bigger */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 if (has_init || (type->t & VT_VLA)) {5727 if (has_init || (type->t & VT_VLA)) {
5722 decl_initializer(type, sec, addr, 1, 0);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 /* patch flexible array member size back to -1, */5729 /* patch flexible array member size back to -1, */
5729 /* for possible subsequent similar declarations */5730 /* for possible subsequent similar declarations */
5730 if (flexible_array)5731 if (flexible_array)
5731 flexible_array->type.ref->c = -1;5732 flexible_array->type.ref->c = -1;
5732 }5733 }
5733 no_alloc: ;5734no_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
5736static void put_func_debug(Sym *sym)5742static void put_func_debug(Sym *sym)
@@ -5802,8 +5808,6 @@ static void func_decl_list(Sym *func_sym) · 65 unmodified lines
5802 'cur_text_section' */5808 'cur_text_section' */
5803static void gen_function(Sym *sym)5809static void gen_function(Sym *sym)
5804{5810{
5805 int saved_nocode_wanted = nocode_wanted;
5806 nocode_wanted = 0;
5807 ind = cur_text_section->data_offset;5811 ind = cur_text_section->data_offset;
5808 /* NOTE: we patch the symbol size later */5812 /* NOTE: we patch the symbol size later */
5809 put_extern_sym(sym, cur_text_section, ind, 0);5813 put_extern_sym(sym, cur_text_section, ind, 0);
@@ -5859,7 +5863,6 @@ static void gen_function(Sym *sym) · 49 unmodified lines
5859 func_vt.t = VT_VOID; /* for safety */5863 func_vt.t = VT_VOID; /* for safety */
5860 func_var = 0; /* for safety */5864 func_var = 0; /* for safety */
5861 ind = 0; /* for safety */5865 ind = 0; /* for safety */
5862 nocode_wanted = saved_nocode_wanted;
5863}5866}
5864 5867
5865ST_FUNC void gen_inline_functions(void)5868ST_FUNC void gen_inline_functions(void)

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