[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] [patch] tcc reports wrong file name for static inline
From: |
Thomas Preud'homme |
Subject: |
Re: [Tinycc-devel] [patch] tcc reports wrong file name for static inline functions |
Date: |
Thu, 18 Sep 2014 23:03:15 +0800 |
User-agent: |
KMail/4.14 (Linux/3.14-2-amd64; KDE/4.14.0; x86_64; ; ) |
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.