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
778778 #endif
779779
780780 define_start = define_stack;
781− nocode_wanted = 1;
782781
783782 if (setjmp(s1->error_jmp_buf) == 0) {
784783 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
55285528 literals). It also simplifies local
55295529 initializers handling */
55305530 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) {
55345532 /* get all init string */
55355533 if (has_init == 2) {
55365534 /* only get strings */
@@ -5569,11 +5567,19 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, · 32 unmodified lines
55695567 macro_ptr = init_str.str;
55705568 next();
55715569
5572− /* if still unknown size, error */
55735570 size = type_size(type, &align);
5574− if (size < 0)
5575− tcc_error("unknown type size");
55765571 }
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+
55775583 if (flexible_array)
55785584 size += flexible_array->type.ref->c * pointed_size(&flexible_array->type);
55795585 /* 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
57205726 }
57215727 if (has_init || (type->t & VT_VLA)) {
57225728 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− }
57285729 /* patch flexible array member size back to -1, */
57295730 /* for possible subsequent similar declarations */
57305731 if (flexible_array)
57315732 flexible_array->type.ref->c = -1;
57325733 }
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+ }
57345740 }
57355741
57365742 static void put_func_debug(Sym *sym)
@@ -5802,8 +5808,6 @@ static void func_decl_list(Sym *func_sym) · 65 unmodified lines
58025808 'cur_text_section' */
58035809 static void gen_function(Sym *sym)
58045810 {
5805− int saved_nocode_wanted = nocode_wanted;
5806− nocode_wanted = 0;
58075811 ind = cur_text_section->data_offset;
58085812 /* NOTE: we patch the symbol size later */
58095813 put_extern_sym(sym, cur_text_section, ind, 0);
@@ -5859,7 +5863,6 @@ static void gen_function(Sym *sym) · 49 unmodified lines
58595863 func_vt.t = VT_VOID; /* for safety */
58605864 func_var = 0; /* for safety */
58615865 ind = 0; /* for safety */
5862− nocode_wanted = saved_nocode_wanted;
58635866 }
58645867
58655868 ST_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