Le vendredi 12 septembre 2014, 17:50:08 Vadim Ushakov a écrit : > > The bug seems to be in decl0(). When it sees a static inline declaration, > it _first_ reads the function body and _then_ saves the body and the file > name in tcc_state->inline_fns. > > If the function is the last declaration, the parser pops the file from the > stack after reading the function. After that, decl0() attempts to read > file->filename and gets the name of the previous file in the stack.
Thanks for the analysis, it helps reviewing the patch. > > The patch is: > > diff --git a/tccgen.c b/tccgen.c > index 5fd127f..f1146db 100644 > --- a/tccgen.c > +++ b/tccgen.c > @@ -6055,7 +6055,11 @@ static int decl0(int l, int is_for_loop_init) > int block_level; > struct InlineFunc *fn; > const char *filename; > - > + > + filename = file ? file->filename : ""; > + fn = tcc_malloc(sizeof *fn + strlen(filename)); > + strcpy(fn->filename, filename); > + > tok_str_new(&func_str); > > block_level = 0; > @@ -6076,9 +6080,7 @@ static int decl0(int l, int is_for_loop_init) > } > tok_str_add(&func_str, -1); > tok_str_add(&func_str, 0); > - filename = file ? file->filename : ""; > - fn = tcc_malloc(sizeof *fn + strlen(filename)); > - strcpy(fn->filename, filename); > + > fn->sym = sym; > fn->token_str = func_str.str; > dynarray_add((void ***)&tcc_state->inline_fns, > &tcc_state->nb_inline_fns, fn); Looks good but please add a testcase. Maybe the example you showed us? Look at tests in test2. Best regards, Thomas
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ Tinycc-devel mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/tinycc-devel
