mirror of
https://github.com/mirror/tinycc.git
synced 2025-03-24 10:00:07 +08:00
three small fixes & three reverts
- tcc.h: msvc doesn't grok __func__ (reverts previous commit) - tccgen.c: fortify tcc against bogus code: - n[sizeof({3;})]; // statement expression outside of function - f(){"123"4}; // tokens with values following each other (also, add "type defaults to int" warning for variables) - tccpe.c: removed a check that caused BSS symbols not to be exported. Whatever that check was meant to prevent. - win32/build-tcc.bat: cmd.exe sometimes doesn't grok '-' in labels - Revert "libtcc: no need to undef" This reverts commit2b7aa2a1e1
. - Revert "tcc.h libtcc.c: remove unused defines" This reverts commit985d963745
. The point of these "unused defines" is to be unused, that is to remind people not to use malloc but please to "use_tcc_malloc", instead.
This commit is contained in:
parent
2b7aa2a1e1
commit
8b69059f66
8
libtcc.c
8
libtcc.c
@ -221,6 +221,10 @@ PUB_FUNC char *tcc_fileextension (const char *name)
|
||||
/********************************************************/
|
||||
/* memory management */
|
||||
|
||||
#undef free
|
||||
#undef malloc
|
||||
#undef realloc
|
||||
|
||||
#ifndef MEM_DEBUG
|
||||
|
||||
PUB_FUNC void tcc_free(void *ptr)
|
||||
@ -417,6 +421,10 @@ PUB_FUNC void tcc_memcheck(void)
|
||||
}
|
||||
#endif /* MEM_DEBUG */
|
||||
|
||||
#define free(p) use_tcc_free(p)
|
||||
#define malloc(s) use_tcc_malloc(s)
|
||||
#define realloc(p, s) use_tcc_realloc(p, s)
|
||||
|
||||
/********************************************************/
|
||||
/* dynarrays */
|
||||
|
||||
|
7
tcc.h
7
tcc.h
@ -1229,11 +1229,16 @@ PUB_FUNC void *tcc_realloc_debug(void *ptr, unsigned long size, const char *file
|
||||
PUB_FUNC char *tcc_strdup_debug(const char *str, const char *file, int line);
|
||||
#endif
|
||||
|
||||
#define free(p) use_tcc_free(p)
|
||||
#define malloc(s) use_tcc_malloc(s)
|
||||
#define realloc(p, s) use_tcc_realloc(p, s)
|
||||
#undef strdup
|
||||
#define strdup(s) use_tcc_strdup(s)
|
||||
PUB_FUNC void _tcc_error_noabort(const char *fmt, ...) PRINTF_LIKE(1,2);
|
||||
PUB_FUNC NORETURN void _tcc_error(const char *fmt, ...) PRINTF_LIKE(1,2);
|
||||
PUB_FUNC void _tcc_warning(const char *fmt, ...) PRINTF_LIKE(1,2);
|
||||
#define tcc_internal_error(msg) tcc_error("internal compiler error\n"\
|
||||
"%s:%d: in %s(): " msg, __FILE__,__LINE__,__func__)
|
||||
"%s:%d: in %s(): " msg, __FILE__,__LINE__,__FUNCTION__)
|
||||
|
||||
/* other utilities */
|
||||
ST_FUNC void dynarray_add(void *ptab, int *nb_ptr, void *data);
|
||||
|
24
tccgen.c
24
tccgen.c
@ -5591,7 +5591,9 @@ ST_FUNC void unary(void)
|
||||
} else if (tok == '{') {
|
||||
int saved_nocode_wanted = nocode_wanted;
|
||||
if (const_wanted && !(nocode_wanted & unevalmask))
|
||||
tcc_error("expected constant");
|
||||
expect("constant");
|
||||
if (0 == local_scope)
|
||||
tcc_error("statement expression outside of function");
|
||||
/* save all registers */
|
||||
save_regs(0);
|
||||
/* statement expression : we do not accept break/continue
|
||||
@ -6950,7 +6952,12 @@ static void block(int is_expr)
|
||||
}
|
||||
|
||||
again:
|
||||
t = tok, next();
|
||||
t = tok;
|
||||
/* If the token carries a value, next() might destroy it. Only with
|
||||
invalid code such as f(){"123"4;} */
|
||||
if (TOK_HAS_VALUE(t))
|
||||
goto expr;
|
||||
next();
|
||||
|
||||
if (t == TOK_IF) {
|
||||
skip('(');
|
||||
@ -7253,6 +7260,7 @@ again:
|
||||
/* expression case */
|
||||
if (t != ';') {
|
||||
unget_tok(t);
|
||||
expr:
|
||||
if (is_expr) {
|
||||
vpop();
|
||||
gexpr();
|
||||
@ -8281,7 +8289,7 @@ static void free_inline_functions(TCCState *s)
|
||||
if parsing old style parameter decl list (and FUNC_SYM is set then) */
|
||||
static int decl0(int l, int is_for_loop_init, Sym *func_sym)
|
||||
{
|
||||
int v, has_init, r;
|
||||
int v, has_init, r, oldint;
|
||||
CType type, btype;
|
||||
Sym *sym;
|
||||
AttributeDef ad, adbase;
|
||||
@ -8312,6 +8320,8 @@ static int decl0(int l, int is_for_loop_init, Sym *func_sym)
|
||||
skip(';');
|
||||
continue;
|
||||
}
|
||||
|
||||
oldint = 0;
|
||||
if (!parse_btype(&btype, &adbase)) {
|
||||
if (is_for_loop_init)
|
||||
return 0;
|
||||
@ -8331,15 +8341,17 @@ static int decl0(int l, int is_for_loop_init, Sym *func_sym)
|
||||
/* special test for old K&R protos without explicit int
|
||||
type. Only accepted when defining global data */
|
||||
btype.t = VT_INT;
|
||||
oldint = 1;
|
||||
} else {
|
||||
if (tok != TOK_EOF)
|
||||
expect("declaration");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (tok == ';') {
|
||||
if ((btype.t & VT_BTYPE) == VT_STRUCT) {
|
||||
int v = btype.ref->v;
|
||||
v = btype.ref->v;
|
||||
if (!(v & SYM_FIELD) && (v & ~SYM_STRUCT) >= SYM_FIRST_ANOM)
|
||||
tcc_warning("unnamed struct/union that defines no instances");
|
||||
next();
|
||||
@ -8350,6 +8362,7 @@ static int decl0(int l, int is_for_loop_init, Sym *func_sym)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
while (1) { /* iterate thru each declaration */
|
||||
type = btype;
|
||||
ad = adbase;
|
||||
@ -8384,6 +8397,9 @@ static int decl0(int l, int is_for_loop_init, Sym *func_sym)
|
||||
/* always compile 'extern inline' */
|
||||
if (type.t & VT_EXTERN)
|
||||
type.t &= ~VT_INLINE;
|
||||
|
||||
} else if (oldint) {
|
||||
tcc_warning("type defaults to int");
|
||||
}
|
||||
|
||||
if (gnu_ext && (tok == TOK_ASM1 || tok == TOK_ASM2 || tok == TOK_ASM3)) {
|
||||
|
4
tccpe.c
4
tccpe.c
@ -922,9 +922,7 @@ static void pe_build_exports(struct pe_info *pe)
|
||||
for (sym_index = 1; sym_index < sym_end; ++sym_index) {
|
||||
sym = (ElfW(Sym)*)symtab_section->data + sym_index;
|
||||
name = pe_export_name(pe->s1, sym);
|
||||
if ((sym->st_other & ST_PE_EXPORT)
|
||||
/* export only symbols from actually written sections */
|
||||
&& pe->s1->sections[sym->st_shndx]->sh_addr) {
|
||||
if (sym->st_other & ST_PE_EXPORT) {
|
||||
p = tcc_malloc(sizeof *p);
|
||||
p->index = sym_index;
|
||||
p->name = name;
|
||||
|
@ -1 +1,2 @@
|
||||
102_alignas.c:4: warning: type defaults to int
|
||||
1 1 1 1
|
||||
|
@ -354,5 +354,16 @@ struct c1 c1 = { 1, { 2, 3, 4 } };
|
||||
struct c2 { int c; struct c1 c1; };
|
||||
struct c2 c2 = { 1, { 2, { 3, 4, 5 }}};
|
||||
|
||||
/******************************************************************/
|
||||
#elif defined test_default_int_type
|
||||
n; // warn
|
||||
f(); // don't warn
|
||||
|
||||
#elif defined test_invalid_global_stmtexpr
|
||||
n[sizeof({3;})]; // crashed in block() due to missing local scope
|
||||
|
||||
#elif defined test_invalid_tokckill
|
||||
f(){"12"3;} // second const token killed the value of the first
|
||||
|
||||
/******************************************************************/
|
||||
#endif
|
||||
|
@ -165,3 +165,12 @@ bar : 3 ; 3
|
||||
|
||||
[test_var_array2]
|
||||
60_errors_and_warnings.c:355: error: flexible array has zero size in this context
|
||||
|
||||
[test_default_int_type]
|
||||
60_errors_and_warnings.c:359: warning: type defaults to int
|
||||
|
||||
[test_invalid_global_stmtexpr]
|
||||
60_errors_and_warnings.c:363: error: statement expression outside of function
|
||||
|
||||
[test_invalid_tokckill]
|
||||
60_errors_and_warnings.c:366: error: ';' expected (got "3")
|
||||
|
@ -124,7 +124,7 @@ for %%f in (*tcc.exe *tcc.dll) do @del %%f
|
||||
%CC% -o tcc.exe ..\tcc.c libtcc.dll %D% -DONE_SOURCE"=0"
|
||||
%CC% -o %PX%-tcc.exe ..\tcc.c %DX%
|
||||
|
||||
@if (%EXES_ONLY%)==(yes) goto :files-done
|
||||
@if (%EXES_ONLY%)==(yes) goto :files_done
|
||||
|
||||
if not exist libtcc mkdir libtcc
|
||||
if not exist doc mkdir doc
|
||||
@ -174,7 +174,7 @@ echo>..\config.texi @set VERSION %VERSION%
|
||||
cmd /c makeinfo --html --no-split ../tcc-doc.texi -o doc/tcc-doc.html
|
||||
:doc-done
|
||||
|
||||
:files-done
|
||||
:files_done
|
||||
for %%f in (*.o *.def) do @del %%f
|
||||
|
||||
:copy-install
|
||||
|
Loading…
Reference in New Issue
Block a user