[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Tinycc-devel] [patch] tcc reports wrong file name for static inline fun
From: |
Vadim Ushakov |
Subject: |
[Tinycc-devel] [patch] tcc reports wrong file name for static inline functions |
Date: |
Fri, 12 Sep 2014 17:50:08 +0800 |
Hello!
tcc reports wrong file name when an error occurs in a static inline function,
if that function is the last in a file. Here is an example:
test.c:
> #include "test.h"
> int test(void)
> {
> return foo();
> }
test.h:
> static inline int foo(void)
> {
> wrong_type_t t = 0;
> return t + 1;
> }
result:
> $ tcc -o test test.c
> test.c:3: error: 'wrong_type_t' undeclared
tcc says it is test.c, however the error is in test.h.
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.
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);
--
Regards,
Vadim Ushakov
- [Tinycc-devel] [patch] tcc reports wrong file name for static inline functions,
Vadim Ushakov <=