From 34b45a69ffcc846d33557ce58424965dde2286a3 Mon Sep 17 00:00:00 2001 From: grischka Date: Sun, 21 Sep 2025 14:47:46 +0200 Subject: [PATCH] Reverts & cleanups - include/stddef.h, tcctest.c Revert "tests/tcctest.c: include stdint.h" This reverts commit 8f23997ca7c7bd34756bbbae1f5363afec422907 We don't want tcctest.c to rely on system include files - libtcc.c: Revert "libtcc.c: Remove unused defines free and realloc" To be unused is the point why they do exist This reverts commit 2f8876410044b3e8d26c79f1f7dfac5b7700a88c. - tcc.c: fix formatting of commit e73529865d97f7699b6a96fca5ecd0d6affe605b - tccpp.c: parse_include(): print skipped include files too (with tcc -vv[v] file) next_nomacro(): faster L"str" parsing - tccgen.c: fix c2y if declaration: * accept like GCC: if (int a = 0, b, c = x; c) * accept as "TCC extension": if (int a = 0, b, c = x) * "speak tcc" with symbol/function names - README: cleanup --- README | 15 ++++++--------- include/stddef.h | 1 - libtcc.c | 4 ++++ tcc.c | 3 ++- tcc.h | 3 ++- tccgen.c | 44 +++++++++++++++----------------------------- tccpp.c | 16 ++++++---------- tests/tcctest.c | 6 ++---- 8 files changed, 37 insertions(+), 55 deletions(-) diff --git a/README b/README index 809dd8d4..7cff0a44 100644 --- a/README +++ b/README @@ -7,9 +7,8 @@ Features: - SMALL! You can compile and execute C code everywhere, for example on rescue disks. -- FAST! tcc generates optimized x86 code. No byte code - overhead. Compile, assemble and link about 7 times faster than 'gcc - -O0'. +- FAST! tcc generates machine code for i386, x86_64, arm, aarch64 or + riscv64. Compiles and links about 10 times faster than 'gcc -O0'. - UNLIMITED! Any C dynamic library can be used directly. TCC is heading toward full ISOC99 compliance. TCC can of course compile @@ -28,15 +27,14 @@ Features: Documentation: ------------- -1) Installation on a i386/x86_64/arm/aarch64/riscv64 - Linux/macOS/FreeBSD/NetBSD/OpenBSD hosts. +1) Installation on Linux, BSD variants or macOS hosts: ./configure make make test make install - Notes: For FreeBSD, NetBSD and OpenBSD, gmake should be used instead of make. + Notes: On BSD hosts, gmake should be used instead of make. For Windows read tcc-win32.txt. makeinfo must be installed to compile the doc. By default, tcc is @@ -83,9 +81,8 @@ when doing 'make test'. 4) Full Documentation -Please read tcc-doc.html to have all the features of TCC. - -Additional information is available for the Windows port in tcc-win32.txt. +Please read tcc-doc.html to have all the features of TCC. Additional +information for the Windows port is in tcc-win32.txt. License: ------- diff --git a/include/stddef.h b/include/stddef.h index 95c6dc79..3d328daa 100644 --- a/include/stddef.h +++ b/include/stddef.h @@ -1,6 +1,5 @@ #ifndef _STDDEF_H #define _STDDEF_H -#define _TINYC_STDDEF typedef __SIZE_TYPE__ size_t; typedef __PTRDIFF_TYPE__ ssize_t; diff --git a/libtcc.c b/libtcc.c index f212981e..6ff551eb 100644 --- a/libtcc.c +++ b/libtcc.c @@ -257,6 +257,10 @@ ST_FUNC void libc_free(void *ptr) free(ptr); } +/* defined to be not used */ +#define free(p) use_tcc_free(p) +#define realloc(p, s) use_tcc_realloc(p, s) + /* global so that every tcc_alloc()/tcc_free() call doesn't need to be changed */ static void *(*reallocator)(void*, unsigned long) = default_reallocator; diff --git a/tcc.c b/tcc.c index 9dfd0bc0..f1f527a5 100644 --- a/tcc.c +++ b/tcc.c @@ -87,7 +87,8 @@ static const char help[] = #ifdef TCC_TARGET_PE " create def file : tcc -impdef lib.dll [-v] [-o lib.def]\n" #endif - " report bugs to the mailing list http://lists.nongnu.org/mailman/listinfo/tinycc-devel\n" + "Discussion & bug reports:\n" + " https://lists.nongnu.org/mailman/listinfo/tinycc-devel\n" ; static const char help2[] = diff --git a/tcc.h b/tcc.h index 75a4a8fd..ee34b169 100644 --- a/tcc.h +++ b/tcc.h @@ -56,7 +56,7 @@ extern long double strtold (const char *__nptr, char **__endptr); # include /* open, close etc. */ # include /* getcwd */ # include /* alloca */ -# ifdef __GNUC__ +# ifndef _MSC_VER # include # endif # define inline __inline @@ -1235,6 +1235,7 @@ PUB_FUNC char *tcc_strdup_debug(const char *str, const char *file, int line); #endif ST_FUNC void libc_free(void *ptr); +/* defined to be not used */ #define free(p) use_tcc_free(p) #define malloc(s) use_tcc_malloc(s) #define realloc(p, s) use_tcc_realloc(p, s) diff --git a/tccgen.c b/tccgen.c index 0c4d3bff..e9250200 100644 --- a/tccgen.c +++ b/tccgen.c @@ -7108,28 +7108,18 @@ static void lblock(int *bsym, int *csym) } } -static void condition_expresion(void) +/* c2y if/switch declaration */ +static void gexpr_decl(void) { - Sym *s; - int decl_ret; - - /* c2y if init decl? */ - if (!(decl_ret = decl(VT_JMPI))) { - /* no, regular if init expr */ - gexpr(); + int v = decl(VT_JMP); + if (v > 1 && tok != ';') { + Sym *s = sym_find(v); + vset(&s->type, s->r, (s->r & VT_SYM) ? 0 : s->c); + vtop->sym = s; } else { - if (decl_ret == 1) - tcc_error("declaration in the controlling expression must have an initializer"); - - if (tok == ';') { - /* finish the push */ - next(); - gexpr(); - } else { - s = sym_find(decl_ret); - vset(&s->type, s->r, s->c); - vtop->sym = s; - } + if (v) + skip(';'); + gexpr(); } } @@ -7153,7 +7143,7 @@ again: if (t == TOK_IF) { new_scope_s(&o); skip('('); - condition_expresion(); + gexpr_decl(); a = gvtst(1, 0); skip(')'); block(0); @@ -7322,7 +7312,7 @@ again: new_scope_s(&o); skip('('); - condition_expresion(); + gexpr_decl(); if (!is_integer_btype(vtop->type.t & VT_BTYPE)) tcc_error("switch value not an integer"); skip(')'); @@ -8654,9 +8644,7 @@ static void pe_check_linkage(CType *type, AttributeDef *ad) /* 'l' is VT_LOCAL or VT_CONST to define default storage type or VT_CMP if parsing old style parameter list - or VT_JMP if parsing c99 for decl: for (int i = 0, ...) - or VT_JMPI if parsing c2y if decl; if (int = 0; ...) -*/ + or VT_JMP if parsing c99 for decl: for (int i = 0, ...) */ static int decl(int l) { int v, has_init, r, oldint; @@ -8669,7 +8657,7 @@ static int decl(int l) oldint = 0; if (!parse_btype(&btype, &adbase, l == VT_LOCAL)) { - if (l == VT_JMP || l == VT_JMPI) + if (l == VT_JMP) return 0; /* skip redundant ';' if not in old parameter decl scope */ if (tok == ';' && l != VT_CMP) { @@ -8896,12 +8884,10 @@ static int decl(int l) } } if (tok != ',') { - if (l == VT_JMP || l == VT_JMPI) + if (l == VT_JMP) return has_init ? v : 1; skip(';'); break; - } else if (l == VT_JMPI) { - tcc_error("declaration in condition can only declare a single object"); } next(); } diff --git a/tccpp.c b/tccpp.c index 9f9d2cf9..fc0d2e8c 100644 --- a/tccpp.c +++ b/tccpp.c @@ -1418,6 +1418,9 @@ static int parse_include(TCCState *s1, int do_next, int test) #ifdef INC_DEBUG printf("%s: skipping cached %s\n", file->filename, buf); #endif + if ((s1->verbose | 1) == 3) /* -vv[v] */ + printf("=> %*s%s\n", + (int)(s1->include_stack_ptr - s1->include_stack), "", buf); return 1; } if (tcc_open(s1, buf) >= 0) @@ -2740,7 +2743,6 @@ maybe_newline: cstr_cat(&tokcstr, (char *) p1, len); p--; PEEKC(c, p); - parse_ident_slow: while (isidnum_table[c - CH_EOF] & (IS_ID|IS_NUM)) { cstr_ccat(&tokcstr, c); @@ -2752,21 +2754,15 @@ maybe_newline: break; case 'L': t = p[1]; - if (t != '\\' && t != '\'' && t != '\"') { - /* fast case */ - goto parse_ident_fast; - } else { + if (t == '\'' || t == '\"' || t == '\\') { PEEKC(c, p); if (c == '\'' || c == '\"') { is_long = 1; goto str_const; - } else { - cstr_reset(&tokcstr); - cstr_ccat(&tokcstr, 'L'); - goto parse_ident_slow; } + *--p = c = 'L'; } - break; + goto parse_ident_fast; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': diff --git a/tests/tcctest.c b/tests/tcctest.c index ff504bf1..6a16e945 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -41,6 +41,8 @@ #define LONG_DOUBLE_LITERAL(x) x ## L #endif +typedef __SIZE_TYPE__ uintptr_t; + /* test various include syntaxes */ #define TCCLIB_INC @@ -62,10 +64,6 @@ #include "tcctest.h" -#ifndef _TINYC_STDDEF -#include -#endif - /* Test two more ways to include a file named like a pp-number */ #define INC(name) #define funnyname 42test.h