1
0
Fork 0
Commit Graph

3469 Commits

Author SHA1 Message Date
noneofyourbusiness e70fec871b
riscv64-tok.h: update with more instructions from the spec
defined tokens for C, M, Ziscr extensions.

separate the base RV32 instructions from the RV64, for potential future
re-use in a RV32-only assembler, from which the RV64-tok can #include

scall, sbreak have been renamed (page 7 of spec),
necessitating some renaming in riscv64-asm.c

riscv-spec-20191213.pdf was used,
in which the "V" extension is not yet ratified.
available under https://riscv.org/technical/specifications/

Tables 16.5–16.7 do not list any "scall"
neither does the privileged spec

3 additional tokens not present in the tables were removed

note that this riscv64-asm.c still contains defects, which will
be addressed in another commit
2023-08-10 14:25:03 +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
grischka 022fb4293b tccpp: #pragma once normalized
In order to detect a "same file" faster, this makes one
restriction to the feature: the basenames are required to
match at least (as in "test.h" and "dir/../test.h")

Also remove obsolete 'pp_once' (cached includes do not persist
across compilations anymore anyway)

This rewrites commits
30fd24abd4
4e363a1728

 3 files changed, 38 insertions(+), 74 deletions(-)
2023-07-31 12:22:10 +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 c92f4f52d9 Update pragma once for file operations
Use open/read/close instead of fopen/fread/fclose for tcc4tcl and ziptcc
2023-06-26 11:19:41 +02:00
herman ten brugge 4e363a1728 Small update on pragma once
Update on calc_file_hash. Use xor instead of +.
Only calculate has if file name differs in search_cached_include.
2023-06-26 06:33:46 +02: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
OldWorldOrdr 5077d4c915 change which to command -v 2023-06-12 03:53:05 -04:00
waltje 583c3b4746 Update to previous patch (remove the strcpy.) 2023-05-29 20:46:44 -04:00
waltje da3a763e97 Small patch to allow for the TCC.EXE (and TCCLIB.DLL) to reside in a (directory under) a "bin/" directory at the same level where the "include/" and "lib/" directories are. This allows one to set the PATH to the (proper) binaries directory and TCC will then "find" itself there. Tested under Windows 7, Windows 8.1 (ARM) and Windows 10+11, but should also be workable for Linux and macOS. 2023-05-26 20:19:21 -04:00
herman ten brugge a46372e910 Add support for constant float compare 2023-05-22 15:09:59 +02:00
grischka 0ec3a40dfd about CONST_WANTED & VT_NONCONST
- integrate CONST_WANTED with nocode_wanted
- expr_const() checks VT_NONCONST
2023-04-25 15:43:38 +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
grischka a045400501 CStrings leakless
avoid memory leaks with lost CStrings on stack after errors.

tccpp.c:
- use/abuse static Cstring tokcstr where possible
tccgen.c:
- use/abuse static Cstring initstr where possible
tcc.h/libtcc.a:
- add 'stk_data' array to track memory pointer on stack
- add macros stk_push/pop() and cstr_new/free_s()
tccasm.c:
- use that
- use char[16] instead of char* for op.constraint
2023-04-25 15:22:20 +02:00
grischka 40131b7e0f MEM_DEBUG thread-safe & tccdbg leakless
libtcc.c:
- guard tcc_realloc/free_debug() with a semaphore
tccdbg.c:
- allow tcc_debug_end() to be called twice safely
2023-04-25 15:22:15 +02:00
grischka 7916cf71cc tcc_error_noabort(): always use this unless compiling
This avoids 'exit(1)' with errors outside of compilation
(nasty in particular with libtcc usage)

As a sideeffect multiple errors can be seen for linker
errors (such as undefined symbols, relocation errors, ...)
2023-04-25 15:22:03 +02:00
grischka 19ef024aa9 lib/armeabi.c: fix zero from/to double conversion
tccgen.c:
- allow cross-compiling 0.0L (cross-compile tcc with tcc)
tccelf.c:
- use alignment of TLS section for PT_TLS
tccpp.c:
- support long double constants on systems that do not support
  long doubles (i.e. mark them (VT_DOUBLE | VT_LONG))
tccdefs.h:
  #define __has_feature() for android
  remove _unaligned (why define a msvc extension under !_WIN32)
2023-04-25 08:59:42 +02:00
grischka 86f3d8e331 tccpp: remove unwanted space with __VA_ARGS__
reported by "vsfos"
https://lists.gnu.org/archive/html/tinycc-devel/2023-04/msg00007.html
2023-04-20 14:18:29 +02:00
herman ten brugge 6a24b762d3 Do not crach when compiling with libtcc. 2023-04-15 15:36:13 +02:00
herman ten brugge 24c930a9b8 Allow _unaligned and __unaligned on WIN32 2023-04-15 15:33:14 +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
Detlef Riekenberg e7262accb6 Print correct values in tcc_print_stats (yarpgen v1)
Value 0 and values >2GB where printed wrong during tests with yarpgen (v1)
Starting the output with a hashtag make it compatible to TAP

--
Regards ... Detlef
2023-03-23 20:02:19 +01:00
Detlef Riekenberg afa05caacf Ignore _unaligned and __unaligned. Required >15years ago, but still present in old code
These extensions where used by other compiler
to generate different code on old cpu's (arm and x86 before pentium/pentiumpro)
to prevent processor exceptions / very high delays when accessing an unaligned pointer.

--
Regards ... Detlef
2023-03-23 17:14:29 +01:00
herman ten brugge 95aab7d687 tests/tcctest.c: Add support for osx with clang 10 2023-03-18 14:02:52 +01:00
Avi Halachmi (:avih) e21523529b configure: OSX/macos: autodetect new_macho value
Use old (=no) if autodetect succeeded and osx ver <= 10, else new.
Override is possible, and now also documented at ./configure --help.
2023-03-18 11:42:48 +02: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
Detlef Riekenberg 7abf2c03d6 fix: Do not define INCLUDE_STACK_SIZE twice
We have that define already in tcc.h
and changing the define in tcc.h breaks compilation of tcc
without this fix.

--
Regards ... Detlef
2023-03-11 14:13:23 +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
herman ten brugge cb3589c56e Increase VSTACK_SIZE to 512.
The yarpgen test code uses very complex expressions.
2023-03-11 07:40:56 +01:00
herman ten brugge 88d5c70bdb Update casted boolean expressions
The problem was that enums can also be present in vset_VT_JMP.
Also see testcode.
2023-03-11 07:35:42 +01:00
Michael Matz ef3eb02ccb Fix type of cond-op
the optimization of a ternary op with two boolean operands had
the same problem (as in the last commit) of loosing the type.
2023-03-10 17:23:55 +01:00
Michael Matz 96b31ba670 Fix casted boolean expressions
the casted type was lost when a delayed bool was finally converted
to a value.  See testcase, in the wrong case the '(unsigned int)' cast
was ignored, and hence the division was signed reulting in -1 instead of
the proper 0x7fffffff.
2023-03-10 16:49:27 +01:00
herman ten brugge 2cb8bddd82 Add attribute nodebug support and skip bitfield padding
The following code:
typedef struct {
  unsigned int a __attribute__((nodebug));
  unsigned int b;
  unsigned int : 32;
  unsigned int c;
} tst;

Supresses a and also suppresses bitfield padding.
So debugger shows only b and c in above example.
2023-03-10 12:41:43 +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 80909254c4 Fix Makefile install target
Update target all before installing
2023-03-09 16:00:46 +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
Brian Callahan 29ae3ed4d5 OpenBSD has removed the syscall() function from its libc, so we
need to use getthrid() directly in lib/bcheck.c
2023-02-23 17:19:37 -05: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
Detlef Riekenberg bdec3c5345 Use unsigned int to count sizes for -bench (YARPgen) (part 2)
I have a testfile created by YARPGen (seed=9), which displayed
a negative bss size without this patch.

* tcc needs also a bigger VSTACK_SIZE (i used 512)

--
bye bye ... Detlef
2023-02-03 18:04:56 +01:00
Detlef Riekenberg b2485d6cd5 Use unsigned int to count sizes for -bench (YARPgen)
I have a testfile created by YARPGen (seed=9), which displayed
a negative bss size without this patch.

* tcc needs also a bigger VSTACK_SIZE (i used 512)

--
bye bye ... Detlef
2023-02-03 01:04:38 +01:00
herman ten brugge 4dc7662a07 Fix preprocessor line directive update
The last commit was not a problem with macos.
The problem was that dwarf version < 5 uses different indexes for
files and directories.
They start at 1 for dwarf version < 5 and 0 for dwarf version >= 5.
2023-01-17 20:08:14 +01:00
Christian Jullien 7874397373 Don't forget to mention the amazing job made by Herman on native macOS. 2023-01-17 15:29:57 +01:00
noneofyourbusiness 4cccba74d2
update changelog 2023-01-17 13:38:04 +01:00