misc. fixes

- tccgen: error out for cast to void, as in
      void foo(void) { return 1; }
  This avoids an assertion failure in x86_64-gen.c, also.
  also fix tests2/03_struct.c accordingly

- Error: "memory full" - be more specific

- Makefiles: remove circular dependencies, lookup tcctest.c from VPATH

- tcc.h: cleanup lib, include, crt and libgcc search paths"
  avoid duplication or trailing slashes with no CONFIG_MULTIARCHDIR
  (as from 9382d6f1a0)

- tcc.h: remove ";{B}" from PE search path
  in ce5e12c2f9 James Lyon wrote:
  "... I'm not sure this is the right way to fix this problem."
  And the answer is: No, please. (copying libtcc1.a for tests instead)

- win32/build_tcc.bat: do not move away a versioned file
master
grischka 2014-01-06 19:56:26 +01:00
parent d443644de3
commit 2bd0daabbe
10 changed files with 46 additions and 54 deletions

View File

@ -362,9 +362,6 @@ tar: tcc-doc.html
rm -rf $(TCC-VERSION)
git reset
Makefile: $(top_srcdir)/Makefile
cp $< $@
.PHONY: all clean tar distclean install uninstall FORCE
endif # ifeq ($(TOP),.)

View File

@ -111,6 +111,3 @@ $(DIR)/exists :
clean :
rm -rfv i386-win32 x86_64-win32 i386 x86_64
Makefile: $(top_srcdir)/lib/Makefile
cp $< $@

View File

@ -214,7 +214,7 @@ PUB_FUNC void *tcc_malloc(unsigned long size)
void *ptr;
ptr = malloc(size);
if (!ptr && size)
tcc_error("memory full");
tcc_error("memory full (malloc)");
#ifdef MEM_DEBUG
mem_cur_size += malloc_usable_size(ptr);
if (mem_cur_size > mem_max_size)
@ -239,7 +239,7 @@ PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size)
#endif
ptr1 = realloc(ptr, size);
if (!ptr1 && size)
tcc_error("memory full");
tcc_error("memory full (realloc)");
#ifdef MEM_DEBUG
/* NOTE: count not correct if alloc error, but not critical */
mem_cur_size += malloc_usable_size(ptr1);

30
tcc.h
View File

@ -169,13 +169,18 @@
#ifndef CONFIG_LDDIR
# define CONFIG_LDDIR "lib"
#endif
#ifndef CONFIG_MULTIARCHDIR
#define CONFIG_MULTIARCHDIR
#ifdef CONFIG_MULTIARCHDIR
# define USE_MUADIR(s) s "/" CONFIG_MULTIARCHDIR
# define ALSO_MUADIR(s) s "/" CONFIG_MULTIARCHDIR ":" s
#else
# define USE_MUADIR(s) s
# define ALSO_MUADIR(s) s
#endif
/* path to find crt1.o, crti.o and crtn.o */
#ifndef CONFIG_TCC_CRTPREFIX
# define CONFIG_TCC_CRTPREFIX CONFIG_SYSROOT "/usr/" CONFIG_LDDIR "/" CONFIG_MULTIARCHDIR
# define CONFIG_TCC_CRTPREFIX USE_MUADIR(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR)
#endif
/* Below: {B} is substituted by CONFIG_TCCDIR (rsp. -B option) */
@ -186,10 +191,8 @@
# define CONFIG_TCC_SYSINCLUDEPATHS "{B}/include;{B}/include/winapi"
# else
# define CONFIG_TCC_SYSINCLUDEPATHS \
CONFIG_SYSROOT "/usr/local/include/" CONFIG_MULTIARCHDIR \
":" CONFIG_SYSROOT "/usr/local/include" \
":" CONFIG_SYSROOT "/usr/include/" CONFIG_MULTIARCHDIR \
":" CONFIG_SYSROOT "/usr/include" \
ALSO_MUADIR(CONFIG_SYSROOT "/usr/local/include") \
":" ALSO_MUADIR(CONFIG_SYSROOT "/usr/include") \
":" "{B}/include"
# endif
#endif
@ -197,15 +200,12 @@
/* library search paths */
#ifndef CONFIG_TCC_LIBPATHS
# ifdef TCC_TARGET_PE
# define CONFIG_TCC_LIBPATHS "{B}/lib;{B}"
# define CONFIG_TCC_LIBPATHS "{B}/lib"
# else
# define CONFIG_TCC_LIBPATHS \
CONFIG_SYSROOT "/usr/" CONFIG_LDDIR "/" CONFIG_MULTIARCHDIR \
":" CONFIG_SYSROOT "/usr/" CONFIG_LDDIR \
":" CONFIG_SYSROOT "/" CONFIG_LDDIR "/" CONFIG_MULTIARCHDIR \
":" CONFIG_SYSROOT "/" CONFIG_LDDIR \
":" CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR "/" CONFIG_MULTIARCHDIR \
":" CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR
ALSO_MUADIR(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \
":" ALSO_MUADIR(CONFIG_SYSROOT "/" CONFIG_LDDIR) \
":" ALSO_MUADIR(CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR)
# endif
#endif
@ -237,7 +237,7 @@
#endif
/* library to use with CONFIG_USE_LIBGCC instead of libtcc1.a */
#define TCC_LIBGCC CONFIG_SYSROOT "/" CONFIG_LDDIR "/" CONFIG_MULTIARCHDIR "/libgcc_s.so.1"
#define TCC_LIBGCC USE_MUADIR(CONFIG_SYSROOT "/" CONFIG_LDDIR) "/libgcc_s.so.1"
/* -------------------------------------------- */
/* include the target specific definitions */

View File

@ -309,7 +309,7 @@ static void vsetc(CType *type, int r, CValue *vc)
int v;
if (vtop >= vstack + (VSTACK_SIZE - 1))
tcc_error("memory full");
tcc_error("memory full (vstack)");
/* cannot let cpu flags if other instruction are generated. Also
avoid leaving VT_JMP anywhere except on the top of the stack
because it would complicate the code generator. */
@ -483,7 +483,7 @@ ST_FUNC void vswap(void)
ST_FUNC void vpushv(SValue *v)
{
if (vtop >= vstack + (VSTACK_SIZE - 1))
tcc_error("memory full");
tcc_error("memory full (vstack)");
vtop++;
*vtop = *v;
}
@ -2348,8 +2348,8 @@ static void gen_assign_cast(CType *dt)
st = &vtop->type; /* source type */
dbt = dt->t & VT_BTYPE;
sbt = st->t & VT_BTYPE;
if (sbt == VT_VOID)
tcc_error("Cannot assign void value");
if (sbt == VT_VOID || dbt == VT_VOID)
tcc_error("cannot cast from/to void");
if (dt->t & VT_CONSTANT)
tcc_warning("assignment of read-only location");
switch(dbt) {

View File

@ -197,7 +197,7 @@ static TokenSym *tok_alloc_new(TokenSym **pts, const char *str, int len)
int i;
if (tok_ident >= SYM_FIRST_ANOM)
tcc_error("memory full");
tcc_error("memory full (symbols)");
/* expand token table if needed */
i = tok_ident - TOK_IDENT;
@ -1528,7 +1528,7 @@ include_done:
c = (define_find(tok) != 0) ^ c;
do_if:
if (s1->ifdef_stack_ptr >= s1->ifdef_stack + IFDEF_STACK_SIZE)
tcc_error("memory full");
tcc_error("memory full (ifdef)");
*s1->ifdef_stack_ptr++ = c;
goto test_skip;
case TOK_ELSE:

View File

@ -27,7 +27,7 @@ ifneq ($(ARCH),i386)
TESTS := $(filter-out btest,$(TESTS))
endif
ifdef CONFIG_WIN32
TESTS := $(filter-out test3,$(TESTS))
TESTS := w32-prep $(filter-out test3,$(TESTS))
endif
ifeq ($(TARGETOS),Darwin)
TESTS := $(filter-out hello-exe test3 btest,$(TESTS))
@ -84,6 +84,9 @@ moretests:
@echo ------------ $@ ------------
$(MAKE) -C tests2
w32-prep:
cp ../libtcc1.a ../lib
# test.ref - generate using gcc
# copy only tcclib.h so GCC's stddef and stdarg will be used
test.ref: tcctest.c
@ -91,41 +94,41 @@ test.ref: tcctest.c
./tcctest.gcc > $@
# auto test
test1: test.ref
test1: tcctest.c test.ref
@echo ------------ $@ ------------
$(TCC) -run $(SRCDIR)/tcctest.c > test.out1
$(TCC) -run $< > test.out1
@if diff -u test.ref test.out1 ; then echo "Auto Test OK"; fi
# iterated test2 (compile tcc then compile tcctest.c !)
test2: test.ref
test2: tcctest.c test.ref
@echo ------------ $@ ------------
$(TCC) $(RUN_TCC) $(RUN_TCC) -run $(SRCDIR)/tcctest.c > test.out2
$(TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out2
@if diff -u test.ref test.out2 ; then echo "Auto Test2 OK"; fi
# iterated test3 (compile tcc then compile tcc then compile tcctest.c !)
test3: test.ref
test3: tcctest.c test.ref
@echo ------------ $@ ------------
$(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $(SRCDIR)/tcctest.c > test.out3
$(TCC) $(RUN_TCC) $(RUN_TCC) $(RUN_TCC) -run $< > test.out3
@if diff -u test.ref test.out3 ; then echo "Auto Test3 OK"; fi
# binary output test
test4: test.ref
test4: tcctest.c test.ref
@echo ------------ $@ ------------
# object + link output
$(TCC) -c -o tcctest3.o $(SRCDIR)/tcctest.c
$(TCC) -c -o tcctest3.o $<
$(TCC) -o tcctest3 tcctest3.o
./tcctest3 > test3.out
@if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
# dynamic output
$(TCC) -o tcctest1 $(SRCDIR)/tcctest.c
$(TCC) -o tcctest1 $<
./tcctest1 > test1.out
@if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
# dynamic output + bound check
$(TCC) -b -o tcctest4 $(SRCDIR)/tcctest.c
$(TCC) -b -o tcctest4 $<
./tcctest4 > test4.out
@if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
# static output
$(TCC) -static -o tcctest2 $(SRCDIR)/tcctest.c
$(TCC) -static -o tcctest2 $<
./tcctest2 > test2.out
@if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
@ -161,9 +164,9 @@ speedtest: ex2 ex3
time ./ex3 35
time $(TCC) -run $(top_srcdir)/examples/ex3.c 35
weaktest: test.ref
$(TCC) -c tcctest.c -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS)
$(CC) -c tcctest.c -o weaktest.gcc.o -I. $(CPPFLAGS) -w $(CFLAGS)
weaktest: tcctest.c test.ref
$(TCC) -c $< -o weaktest.tcc.o $(CPPFLAGS) $(CFLAGS)
$(CC) -c $< -o weaktest.gcc.o -I. $(CPPFLAGS) -w $(CFLAGS)
objdump -t weaktest.tcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.tcc.o.txt
objdump -t weaktest.gcc.o | grep ' w ' | sed -e 's/.* \([a-zA-Z0-9_]*\)$$/\1/' | LC_ALL=C sort > weaktest.gcc.o.txt
diff weaktest.gcc.o.txt weaktest.tcc.o.txt && echo "Weak Auto Test OK"
@ -220,7 +223,5 @@ cache: tcc_g
clean:
$(MAKE) -C tests2 $@
rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.gcc *.exe \
hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h
Makefile: $(SRCDIR)/Makefile
cp $< $@
hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h \
../lib/libtcc1.a

View File

@ -6,7 +6,7 @@ struct fred
int natasha;
};
void main()
int main()
{
struct fred bloggs;

View File

@ -96,6 +96,3 @@ all test: $(TESTS)
clean:
rm -vf fred.txt *.output
Makefile: $(top_srcdir)/tests/tests2/Makefile
cp $< $@

View File

@ -63,5 +63,5 @@ del *.o
echo>..\config.texi @set VERSION %VERSION%
if not exist doc md doc
makeinfo --html --no-split -o doc\tcc-doc.html ../tcc-doc.texi
if exist tcc-win32.txt move tcc-win32.txt doc\
copy ..\tests\libtcc_test.c examples\
copy tcc-win32.txt doc
copy ..\tests\libtcc_test.c examples