Hi. I've been using tcc for a while and I found some bugs and made some patches.
Please consider for inclusion. The first takes symlinks into account with header file caching (I need it with my build setup which uses a symlink in a weird way -- gcc and clang don't have problems with it but tcc did). The second fixes stringification with derived types. I noticed tcc stringified them wrong (like `void *(int)(int, void *(int))` where it should be `void (*(int, void (*)(int)))(int)`). The last one makes tcc ignore static and restrict inside of []. C11 allows these inside parameter declarations (with implications only on performance and compile-time checking), so I think tcc might as well silently accept them. Thanks for considering the patches and thanks for the work on tcc. Regards, Petr S.
From ad5f465206cde94cbd1e246847433ba9025cf5b7 Mon Sep 17 00:00:00 2001 From: Petr Skocik <[email protected]> Date: Tue, 26 Sep 2017 14:35:07 +0200 Subject: [PATCH 1/4] take symlinks into account when resolving includes --- tccpp.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tccpp.c b/tccpp.c index 76f9e42..a658fa7 100644 --- a/tccpp.c +++ b/tccpp.c @@ -19,6 +19,7 @@ */ #include "tcc.h" +#include <limits.h> /********************************************************/ /* global variables */ @@ -1806,6 +1807,8 @@ ST_FUNC void preprocess(int is_bof) n = 2 + s1->nb_include_paths + s1->nb_sysinclude_paths; for (; i < n; ++i) { char buf1[sizeof file->filename]; + char pathbuf[PATH_MAX]; + CachedInclude *e; const char *path; @@ -1832,7 +1835,17 @@ ST_FUNC void preprocess(int is_bof) } pstrcat(buf1, sizeof(buf1), buf); + if(NULL!=realpath(buf1, pathbuf)){ + size_t len = strlen(pathbuf); + if(len+1>sizeof(buf1)) + buf1[0]=0; + else + strcpy(buf1,pathbuf); + }else + buf1[0]=0; + e = search_cached_include(s1, buf1, 0); + if (e && (define_find(e->ifndef_macro) || e->once == pp_once)) { /* no need to parse the include because the 'ifndef macro' is defined (or had #pragma once) */ -- 2.15.1
From d57f872513dfd6ebded001e6b1f2a72a88ee03d5 Mon Sep 17 00:00:00 2001 From: Petr Skocik <[email protected]> Date: Fri, 16 Mar 2018 00:26:16 +0100 Subject: [PATCH 2/4] patch type_to_str to handle complex function-ptr decls better Code like: #include <signal.h> int main() { _Generic(signal, int: 0); } should fail with error: type 'extern void (*(int, void (*)(int)))(int)' does not match any association not error: type 'extern void *(int)(int, void *(int))' does not match any association --- tccgen.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tccgen.c b/tccgen.c index 5265e49..08cc5ec 100644 --- a/tccgen.c +++ b/tccgen.c @@ -19,7 +19,6 @@ */ #include "tcc.h" - /********************************************************/ /* global variables */ @@ -2934,17 +2933,26 @@ static void type_to_str(char *buf, int buf_size, break; case VT_FUNC: s = type->ref; - type_to_str(buf, buf_size, &s->type, varstr); - pstrcat(buf, buf_size, "("); + buf1[0]=0; + if(varstr&&*varstr&&'*'==*varstr){ + pstrcat(buf1, sizeof(buf1), "("); + pstrcat(buf1, sizeof(buf1), varstr); + pstrcat(buf1, sizeof(buf1), ")"); + } + pstrcat(buf1, buf_size, "("); sa = s->next; while (sa != NULL) { - type_to_str(buf1, sizeof(buf1), &sa->type, NULL); - pstrcat(buf, buf_size, buf1); + char buf2[256]; + type_to_str(buf2, sizeof(buf2), &sa->type, NULL); + pstrcat(buf1, sizeof(buf1), buf2); sa = sa->next; if (sa) - pstrcat(buf, buf_size, ", "); + pstrcat(buf1, sizeof(buf1), ", "); } - pstrcat(buf, buf_size, ")"); + if(s->f.func_type == FUNC_ELLIPSIS) + pstrcat(buf1, sizeof(buf1), ", ..."); + pstrcat(buf1, sizeof(buf1), ")"); + type_to_str(buf, buf_size, &s->type, buf1); goto no_var; case VT_PTR: s = type->ref; -- 2.15.1
From d0daed5a10211a723ac23d7d6644d12744a362d4 Mon Sep 17 00:00:00 2001 From: Petr Skocik <[email protected]> Date: Fri, 23 Mar 2018 13:19:58 +0100 Subject: [PATCH 3/4] Don't fail on const/restrict/static/* inside [] This patch makes tcc ignore them. Normally (as per the C standard), They should be only applicable inside parameter arrays and affect (const/restrict) the pointer the array gets converted to. --- tccgen.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tccgen.c b/tccgen.c index 08cc5ec..3770ce3 100644 --- a/tccgen.c +++ b/tccgen.c @@ -4344,8 +4344,14 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td) int saved_nocode_wanted = nocode_wanted; /* array definition */ next(); - if (tok == TOK_RESTRICT1) - next(); + for(;;){ + switch(tok){ + default: break; + case TOK_RESTRICT1: case TOK_RESTRICT2: case TOK_RESTRICT3: + case TOK_STATIC: case TOK_CONST1: case '*': + next(); continue; + }; break; + } n = -1; t1 = 0; if (tok != ']') { -- 2.15.1
_______________________________________________ Tinycc-devel mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/tinycc-devel
