Commit Graph

326 Commits

Author SHA1 Message Date
grischka
c88b19966c tccrun: exit() via rt_longjmp()
- new LIBTCC API tcc_setjmp() to allow longjmps & signals
  from compiled code back to libtcc per TCCState
- new LIBTCC API tcc_set_backtrace_func() to handle backtrace output
- move c/dtor/atexit stuff to runtime (lib/runmain.c)
- move bt-log.o into libtcc1.a
- add timeouts to github action (beware, it did happen to hang
  infinitely in the signal handler at some point)
2024-02-15 18:45:49 +01:00
grischka
7b9f19eaab tccpp: macro cleanup
- remove TOK_NOSUBST, mark the token itself instead
- get_tok_str(); mask out SYM_FIELD & update uses
- next(): optimize (~5% faster with tcc -E)
- tok_flags: remove some redundancy
- parse_define(): do not remove spaces around '##' and after '#'
    and mark macros with '##' as MACRO_JOIN to avoid unnecessary
    call to macro_twosharps(mstr):
- next_nomacro(): removed, next_nomacro1(): renamed to next_nomacro()
- next_argstream(): cleanup & new function peek_file()
- macro_subst_tok(): handle special macros (__DATE__ etc.)
  like normal macros if they are #defined
- -DPP_DEBUG : more structured output
- pp_error(): better preprocessor expression error message
- tcctok.h: sort basic keywords (somehow)
- testspp/Makefile: generate .expect with 'make testspp.##+'
- tcc.c: tcc -E -o file : put unixy LFs also on windows
2024-02-09 18:38:14 +01:00
grischka
da0d43903b review recent commits
tccpp.c:
 - revert "Preprocessor fix + new testcase"
   Fix was not a fix and nobody could understand the test.
   This reverts 6379f2ee76
 - better fix and add new test (pp/18.c)

tccgen.c:
 - remove global variables 'in_sizeof', 'constant_p'
 - rework comma expression (gexpr())
 - merge func/data 'alias_target' codes
   (See 08c777053c)
 - move call to do_Static_assert()
 - better error: "expression expected before '%s'"
 - fix "statement after label"
    - remove unnecessary second parameter to block()
    - remove unnecessary call to decl()
    - revert changes to old C89 test file
    See 7f0a28f6ca

tccelf.c:
 - rework "...make undefined global symbol STT_NOTYPE"
   (See f44060f8fc)
 - move tccelf_add_crtbegin() from libtcc.c

tcctest:
 - unfix K&R fix (keep old look of K&R functions)

tccrun.c:
 - exit(0) returns 0

libtcc.c:
 - move #defines for -dumpmachine
 - more explicit error "file not found"
   (as opposed to error while loading file)

tccpe.c, x86_64-gen.c, i386-asm.c, tccasm.c:
 - use R_X86_64_PLT32 for functions on x86_64-win32

tccdefs.h
 - empty #defines for _Nonnull, __has_builtin(), etc.

configure:
 - Simpler "macOS .dylib ... VERSION letters."
   (See 6b967b1285)

Makefile:
 - macOS version also
 - add cross searchpaths for packages

build.yml:
 - disable codesign on macos-11 (doesn't seem to work)
2024-02-04 18:18:40 +01:00
herman ten brugge
bbe2e5a421 Allow declarations in case statement
This now works:

 case 1:
    int z = 123;
    break;
2024-01-16 07:51:56 +01:00
herman ten brugge
c13bbb5cb5 Add type promotion in comma expression and update testcase 94 2024-01-06 07:54:34 +01:00
Rob Pilling
fb164e0ab4 Error out for incomplete type initialisation 2023-11-26 09:29:06 +00:00
Reimar Döffinger
36f53cdc3b Revert "tests: Add support for codesigning command."
This reverts commit ece74ceaaf.

codesigning is already supported via --config-codesign.
This patch actually broke testing for tcc builds with
that set.
2023-10-30 19:08:57 +01:00
Reimar Döffinger
ece74ceaaf tests: Add support for codesigning command.
Allows running the tests out-of-the-box on macOS.
Also delete *.dylib in tests2 dir on "make clean".
One remaining issue on macOS 14.1 is that the
-undefined warning option no longer works,
thus breaking test3 and test1b.
2023-10-29 17:06:59 +01:00
herman ten brugge
31206a5bb8 Fix tests/tests2/Makefile for win32 2023-09-07 20:19:42 +02:00
herman ten brugge
9bb9a04b5f Small fixes
The testcases 22_floating_point and 24_math_library did not work with
make tcov-test
Add -lm for these in tests/tests2/Makefile

gcc -fanalyzer complains about tcc_malloc and tcc_realloc because
malloc(0) and realloc(ptr, 0) is not tested correctly.
2023-09-07 20:05:51 +02:00
grischka
086870addd configury update & bump VERSION to 0.9.28rc
configure:
- option --targetos=... for cross build
- cleanup

win32/build-tcc.bat:
- option -b <bindir>
- make 'libtcc1.a' and cross-prefix-libtcc1.a
  (same convention as with makefile)

Makefile:
- streamline tcov-tests, help, etc.

workflow/build.xml: simplify
- using "windows-2019" runner (instead of windows-latest)
  because its msys seems more complete and has no problems
  with the 96_nodata_wanted.test either.

Changelog,TODO,USES,tcc-doc.texi: update
2023-09-06 22:42:52 +02:00
herman ten brugge
ff2a372a9a Add tcov support in Makefile
The following targets are added:
testc / testc2.all / testc2.37 / testc2.37+ / testc2.37-
testcpp.all / make testcpp.17
This allows to check that the testcase(s) test the code modified.
See Makefile tests/pp/Makefile tests/tests2/Makefile

lib/tcov.c: Fix while loops with fgets.

tcc.h: Fix tcc_p compilation with latest gcc

tests/tests2/22_floating_point.*: Better test floating point
2023-08-31 11:09:49 +02:00
herman ten brugge
b50a0bdf31 Add bound checking for test 132 2023-08-30 16:44:44 +02:00
herman ten brugge
598134fff6 Undo part of incr_offset patch.
The incr_offset offset code was not working with bounds checking.
So I reverted part of tccgen.c.
See new test code 132.

Also added some debugging code that prints location of
bounds checking calls. Needed this to find the problem.
See lib/bcheck.c, lib/bt-dll.c, lib/bt-exe.c, lib/bt-log.c, tccrun.c
2023-08-30 16:10:39 +02:00
grischka
c29420ab0d tccgen: update "Fix invalid load generated by gfunc_return()"
tccgen.c:
- new function incr_offset(int) to increment a lvalue
- use it in gv/vstore to load/store from/to two-word types
- use it to advance the pointer to struct fields
- use it to load/store structs passed in registers
- structs: always assume that reg-classes of registers are 2^n
- adjust stack space when regsize > sizeof the_struct

x86_64-gen.c:
- return regsize=16 for VT_QLONG/QFLOAT

i386-gen.c:
- pass structs of size(8) as two VT_INT rather than one VT_LLONG
  (both should work now)

fixes a82aff3337
fixes fd6d2180c5 (slightly)
2023-07-31 12:22:15 +02:00
herman ten brugge
fd6d2180c5 Align stack when returning structs.
The stack was not aligned when a returned structure was stored on stack.
This resulted in destoying of previous values stored on stack.
See testcase 119 (tst_struct_return_align) where value d is overwritten.
2023-07-31 09:24:06 +02:00
herman ten brugge
5b28165fbf Fix test 131 for 32 bits targets 2023-07-05 19:28:58 +02:00
Yao Zi
a82aff3337
Fix invalid load generated by gfunc_return()
On backends that rely on gfunc_return() to handle structures
  returned in registers (like RISC-V), gfunc_return() may generate
  invalid loads for structures without VT_LOCAL and VT_LVAL. This
  commit fixes it and adds a regression test
  (131_return_struct_in_reg)
2023-07-02 04:02:36 +08:00
herman ten brugge
30fd24abd4 Allow different names for pragma once
pragma once can now be used with
test.h
./test.h

and other references to the same file just like gcc/clang.

On linux we can use stat and st_ino to check for the same file.
On windows the st_ino does not work so we calculate a file hash
if the size of the file differs and then compare the hash.
2023-06-25 20:23:58 +02:00
herman ten brugge
a46372e910 Add support for constant float compare 2023-05-22 15:09:59 +02:00
grischka
bb93bf8cd2 stuff & etc..
- tccpp.c: rename ... to __TCC_BCHECK__/__TCC_BACKTRACE__
- libtcc.c: correct total line count
- libtcc.c: support -run -- args... (instead of -run @ args ...)
- Makefile/build-tcc.bat: streamline GITHASH string somewhat
- bt-exe.c: avoid redef of pstrcpy() with 'tcc -bt tcc.c ...'
2023-04-25 15:22:31 +02:00
Ziyao
b006b98334
Fix passing of large function arguments on riscv64
- Correct stack adjustment in gfunc_call()
- Add a regression test (130_large_argument)
2023-04-09 06:06:10 +08:00
Michael Matz
4dc4e93f1d Fix 128_run_atexit.c on linux
if we include standard headers on glibc-based systems then
we can't use '__attribute__' (those are defined away for unknown
compilers) but must use '__attribute' (or #undef that token).
2023-03-13 17:01:35 +01:00
grischka
19e3e10e4b small scopes cleanup etc.
tccgen.c:
- just track local_stack for small scopes (can't declare variables)
- fix a vla problem with nested scopes
- move debug N_L/RBRAC into curly braced block

Also:
- tccpp.c: move 'label_...' functions to tccgen.c
- tccpp.c: let get_tok_str() say "<no name>" for anonymous symbols
- tcctest.c: let __pa_symbol() work for memory > 2GB
- 119_random_stuff.c: revert strtoll test (no reason to test libc)
- tccdefs.h/tcctest.c: enable bit fncs for _WIN32
- Makefile:
  - use i686-linux-gnu instead of i386-linux-gnu for cross-i386
  - update 'make help'
  - revert umplicit 'make all' with 'make install' (but print warning)
2023-03-12 20:40:50 +01:00
grischka
5f08561e10 Revert ""Fix" nocode_wanted in expr_landor"
instead in vcheck_cmp(), pass the CODE_OFF_BIT to generators
unless other nocode purposes are set.

This reverts commit cad8739594.

Also in 128_run_atexit.c:
avoid line output disorder which may happen on windows when
tcc itself and runned code are using two different printf
implementations and tcc would print the "[Returns 1]" above
any output from the runned test.
2023-03-12 13:39:07 +01:00
herman ten brugge
cad8739594 Fix nocode_wanted in expr_landor
The generated code by yarpgen failed. I traced the problem to
expr_landor. The problem was that nocode_wanted was removing
too much code.
See also testcase 33.
2023-03-11 07:51:00 +01:00
Michael Matz
2cf3a6eb4d Fix more jumpopts (in ternary op)
the code in expr_cond save nocode_wanted around some parts of
expression evaluation, but at the wrong spots.  If the evaluation
of the condition itself (e.g. in the testcase the first whole ternary
expression) resulted in CODE_OFF, then that was saved, and restored
before return, even if in-between codegen would have CODE_ON'ed already.
Thus the whole CODE_OFF state bled out to outside the expression
evaluation and also disabled the whole if-block.  Found by yarpgen v1
(seed 64).
2023-03-09 18:23:16 +01:00
herman ten brugge
ec81877fa7 Fix test90 for 32 bits targets
Should have used 'long long' instead of 'long' for 32 bits targets.
2023-03-09 16:11:39 +01:00
herman ten brugge
3f0a1719dc Fix init bitfield padding with size 32/64
The init code did not work for padding bitfields with size 32 and 64.
2023-03-09 15:53:48 +01:00
Michael Matz
c771cb52fa Fix code suppression during nocode_wanted
we activate code (CODE_ON) only when the target labels are used,
which doesn't happen during nocode_wanted regions.  So, we cannot
just switch off code either during nocode_wanted regions, nothing
would switch it on again (except in the happy coincidences when we
outright save/restore nocode_wanted).  See the testcase for one
example, reduced from code generated by yarpgen: in
  ext = (xxx || 1)           // #1
        || ((xxx && 1) || 1) // #2
code is first suppressed in #1 normally, then (before this commit)
was suppressed via CODE_OFF during #2 (via indirect gjmp),
then the suppression from #1 was undone, but nothing undoes the
suppression from #2 anymore as everything therein was generated
while nocode_wanted was active.

So, we would either need to save/restore nocode_wanted around
some more expressions, activate CODE_ON also with unused labels (breaks
some optimizations we want), or deactivate CODE_OFF only when not
already in nocode_wanted state.  This does the latter.
2023-03-07 18:10:02 +01:00
Petr Skocik
ccc1651075 Create scopes for switches/whiles/do-whiles
The C standard has required this since at least C99.
A new scope should also be created for ifs, but that's currently
breaking tests2/122_vla_reuse.
2023-03-05 22:31:40 +01:00
Michael Matz
605538f46d Fix sym_scope of typedefs
Sym.sym_scope and Sym.f (FuncAttr) share space, so blindly setting
one clobbers the other.  Right now this only leads to missing errors
on incompatible typedefs (see testcase), which this commit fixes.

But it points to a larger problem:
Generally we can only manipulate Sym.f for anonymous and field symbols,
not for anything that has a top-level name (basically any proper decl),
because the latter use sym_scope.  Luckily the functions type always
contains an anonymous symbol (in sym->type.ref), so we can use that.
But some of the functions attributes actually _do_ apply to the decl,
not the type (e.g. always_inline), so we still have a problem possibly,
when we update an pre-existing type that may already be shared with
another decl.

Would need untangling and perhaps using accessor functions that check
that Sym.f and Sym.sym_scope aren't used for the same symbol.
2023-02-22 17:59:31 +01:00
herman ten brugge
7ed9c95ae7 Allow parallel build testsuite 2022-12-27 14:11:18 +01:00
Petr Skocik
ea0c57e90a Allow _Static_assert declarations in structs
This usage has been part of the C grammar since C11
(http://port70.net/~nsz/c/c11/n1570.html#6.7.2.1) and is
also supported by gcc and clang.
2022-12-10 01:12:44 +01:00
herman ten brugge
657262c7e5 Enable testcases on apple and x86_64 2022-12-06 08:09:16 +01:00
herman ten brugge
6b398686d6 Fix bounds checking without -run on macos
Update tccrun.c to detect rebase for dwarf debug info.
Enabled testcase 126 on macos.
Add prologue_end/epilogue_begin supoort in tcc.h, tccdbg.c, tccgen.c.
2022-12-02 13:09:47 +01:00
herman ten brugge
fef701b57f Allow on_exit to be used with -run
Added on_exit support for tcc -run.
Also fixed the last atexit code.
Updated testcase 128
Fixed test/test2/Mafile for testcase 126
2022-12-02 07:11:55 +01:00
herman ten brugge
ac0604a4d4 Allow atexit to be used with -run
Add atexit code to tccrun.c and added testcase 128
2022-11-29 21:13:20 +01:00
herman ten brugge
065b401c6e Fix static assert with empty string 2022-11-29 19:45:05 +01:00
herman ten brugge
747ad409ac New update tccmacho.c
Fix for external functions as pointers in data section.
See testcase 119 and tccmacho.c in check_relocs.

Make bind/rebase code faster in bind_rebase_import.
- Move reloc check out of loop
- Because relocs are sorted we can do bind/rebase by page.

Change name head into seq in trie code.

Remove unused code in bind_rebase.
2022-11-28 11:19:33 -06:00
herman ten brugge
28fa4d3db6 Add strncat and strrchr to bounds checking 2022-11-25 00:31:32 -06:00
herman ten brugge
f89a6f12a7 Fix atomic test_and_set and clear
The __atomic_test_and_set and __atomic_clear code was correct.
They needed locking.
Replaced to code with assembly code.
The changes are in include/stdatomic.h, lib/stdatomic.c, lib/atomic.S
Enabled tests/tests2/124_atomic_counter.c for apple again.

Also moved lib/fetch_and_add.S code to lib/atomic.S.
Removed lib/fetch_and_add.S
Adjusted lib/Makefile
2022-11-17 05:57:21 -06:00
herman ten brugge
c8ef84c854 Add support for apple m1
The apple m1 uses position independent executables (pie).
I have implemented this in tccmacho.c

Apple also uses the stack different for var_args.
Also characters are signed instead of unsigned.
This is implemented in arm64-gen.c/tccdefs.h

Add bounds checking lib to lib/Makefile.

Add underscore support in lib/atomic.S and lib/fetch_and_add.S

Disable __clear_cache in lib/lib-arm64.c (Use system version).
I will try to fix this in future push.

Disable test_asm_call in tests/tcctest.c. Clang does not support @plt.
Also disable weak symbols test.
I will try to fix weak support in future push.

Disable tests/tests2/124_atomic_counter.c for 64BITS.
This is a bug in the atomic code and will be fixed in future push.

You have to use --dwarf configure option. stabs only works with -run.

tested on apple x86_64(10.5) and arm64(12.3).
2022-11-16 12:52:51 -06:00
Christian Jullien
8eabf67e1e Fix typo in tst_strtoll_strtoull. The wrong function was called for unsigned long long type. 2022-11-12 06:55:39 +01:00
Christian Jullien
6219b2de00 Add tests on Windows for strtoll and strtoull. Tests can probably be used on all systems. 2022-11-11 07:12:49 +01:00
herman ten brugge
79a8229fb5 Add atomic functions for arm/arm64/riscv
Make code more compatible with gcc. Change
__atomic_store
__atomic_load
__atomic_exchange
__atomic_compare_exchange

Also add (include/stdatomic.h, lib/stdatomic.c):
atomic_thread_fence
atomic_signal_fence
atomic_is_lock_free

And gcc extensions (tcctok.h, tccgen.c, lib/stdatomic.c):
__atomic_fetch_nand
__atomic_and_fetch
__atomic_sub_fetch
__atomic_or_fetch
__atomic_xor_fetch
__atomic_and_fetch
__atomic_nand_fetch

Add new file lib/atomic.S with assembly code for __atomic_compare_exchange_n
for arm/arm64/riscv. Also update lib/Makefile.

Update testcode in 124_atomic_counter and 125_atomic_misc to test new functions.
Also update tests/tests2/Makefile to run tests on arm/arm64/riscv.
2022-10-16 18:51:56 +02:00
grischka
d76e03232b win64: hi-mem adjustments
- x86_64-link.c:
  ignore relocation overflow to undefined (weak) symbols
- 104_inline.test:
  test lower 32 bits only
- tccpe.c:
  support -Wl,--image-base=... above the 32bit range
2022-10-13 20:32:47 +02:00
herman ten brugge
76b88e22a4 Fix last __has_include update
After this last change the radare2 project did not compile anymore.

Start with BOL flag after include ends in tccpp.c.
Update testcase 18.
2022-09-12 11:37:47 +02:00
grischka
20a1ebf854 tccpp : get rid of 'ch'
- also simplify parse(_line)_comment() and parse_pp_string()
- fixes a continuation problem in strings (see tcctest.c)
- no differences in performance could be observed

161 insertions(+), 246 deletions(-), less 85 lines
2022-08-18 11:34:36 +02:00
herman ten brugge
0f72db09ab Add testcase __has_include and __has_include_next 2022-08-16 20:53:57 +02:00