Commit Graph

172 Commits

Author SHA1 Message Date
herman ten brugge
4a2e33d160 Update bounds checking.
The bounds checking code has now enabled gen_bounded_ptr_add tests.
This makes the code slower but finds more errors.
I had to correct some things in tcc to make it work.
- Fixed off by one in lib/bcheck.c
- Corrected tccelf.c sym_versions.
- Disabled USE_TAL when using bounds checking.
- Fixed cstr_printf va_start.
- Fixed tests/tests2/46_grep.c off by one error.
- Updated gen_bounded_ptr_add in x86_64-gen.c
- Fixed x86_64-link.c pointer diff.
For gen_vla_alloc now always use alloca call when bounds checking.
Added line/filename in %rax before bound calls to find location of error.
2019-12-12 12:56:06 +01:00
herman ten brugge
4461f38a9e Fix bounds checking for linux/windows 2019-12-10 08:07:25 +01:00
herman ten brugge
df72b8d487 Add windows constructor/destructor support 2019-11-27 18:29:12 +01:00
Christian Jullien
25781e4552 Fix float conversion in arm64 backend 2019-11-08 07:55:05 +01:00
herman ten brugge
96f1fb1da0 rename testcase 2019-10-29 12:02:58 +01:00
herman ten brugge
fadfc118e5 Fix sse calling bug 2019-10-29 07:19:42 +01:00
herman ten brugge
800c3a5e0b Add constructor/destructor support 2019-10-29 07:02:58 +01:00
Pursuer2
a7b37f9c63 Fix bug in gen_cvt_ftoi1. Add test 107_stack_safe for this fix.
(Thanks to the support of herman ten brugge)
2019-10-24 00:57:59 +08:00
herman ten brugge
749dd15ee8 Fix testcase for elf version 2019-10-23 13:14:41 +02:00
herman ten brugge
66a14a1e33 Add testcase for elf_version 2019-10-22 20:45:03 +02:00
herman ten brugge
b073a9c103 Add testcase for elf_version 2019-10-22 20:43:30 +02:00
grischka
7b8799e5ff tccgen.c: local extern decls: copy s->ref for VT_PTR too
This fixes the issue

    int main() { extern char *x; }
    void main1() { extern char *x; }
    t2.c:5: error: incompatible types for redefinition of 'x'

(reported by Giovanni Mascellani 2019/07/16)
2019-09-08 16:59:17 +02:00
Michael Matz
9e429dbef0 Fix invalid size with GNU designated initializers
the uninitialized cumofs was leading to random sizes for
the memset when initializing local structures, potentially
leading to segfaults from it.  Only a problem with GNU
designated initializers, which we didn't test very well.
See testcase.
2019-07-21 21:14:58 +02:00
grischka
1b57560502 nocode, noreturn
A more automatic approach to code suppression (aka. nocode_wanted)

The simple rules are:
- Clear 'nocode_wanted' at (im/explicit) label IF it was used
- Set 'nocode_wanted' after unconditional jumps

Also in order to test this then I did add the "function might
return no value" warning, and then to make that work again I
did add the __attribute__((noreturn)).

Also moved the look ahead label check into the type parser
to gain a little speed.
2019-06-24 11:40:01 +02:00
grischka
8569048031 work on local extern declarations
Example:
    int a = 1;
    void f(void)
    {
        int a = 2;
        {
             extern int a; // = 1 !!
             ....

To get this (more) correctly there is a new function to copy
syms between local to global stacks.

Also, this patch changes the meaning of VT_EXTERN back
to the simpler and IMO more useful notion of
    DECLARED but not (yet) DEFINED.
and that for both variables and functions.  That is, VT_EXTERN
in tcc doesn't have to do with the keyword 'extern' necessarily.

Also this patch does allow
    int x[];
as alias for
    extern int x[];
(as do gcc and msvc)
2019-06-24 11:38:32 +02:00
Pascal Cuoq
cbbba01b46 reject invalid arrays in post_type() 2019-06-24 10:28:44 +02:00
Avi Halachmi (:avih)
6599483304 test 104: fix out-of-tree build+test
This was broken, and now works again:
mkdir build && cd build && ../configure && make && make test
2019-06-22 09:47:57 +03:00
grischka
e6d8f9a8bb test 104: adjust to (unwritten) tests2 suite conventions
... which IMO are:

1) files don't need a _test suffix because all files in
   the directory are tests ;)

2) we test the BEHAVIOR of the program, rather than its
   binary bit contents.

Ok, but nobody said a test can't use two files ;)

(where the 104+_ construct is meant to prevent the file
from being picked up by the makefile as a test on its own).
2019-06-22 00:26:31 +02:00
Avi Halachmi (:avih)
5dfcc7506c test 104: simplify, ensure sort locale, parametric tcc
Previously test 104 used a combination of *nix tools and system() calls
to emulate a `sh` script, which required split code paths for windows
due to different shell and different absolute path representation.

Also, it used a hardcoded tcc binary path, didn't set locale for sort.

Now the tools are used from a `sh` script which the program generates
and invokes, tmp files are at CWD and no conversion is required, tcc
path is taken from Makefile (exported), and `sort` uses LC_ALL=C.
2019-06-21 22:36:09 +03:00
Christian Jullien
d39c49db2d Remove empty conditional _WIN32 code 2019-06-18 15:05:46 +02:00
Christian Jullien
78ee3eb7c7 Add Windows support for tests of inline functions - test 104 2019-06-18 14:29:58 +02:00
Michael Matz
3980e4a5b9 Add testcase for 69a46b0
that fixed mingw but also fixed the problem for which the testcase
is now added.
2019-06-17 19:08:08 +02:00
Michael Matz
4dfc27b101 Stricter C99 inline tests
these three functions are external definitions, and so need
to be emitted even without any references.
2019-06-17 03:33:52 +02:00
Petr Skocik
587e1f5598 standard conformant inline functions
- add tests for standard conformant inline functions
- implement it

The  old tinycc failed to provide a conforming implementation
of non-static inlines.  It would expose external symbols where it
shouldn't and hide them where it should expose them.

This commit provides a hopefully comprehensive test suite
for how things should be done. The .expect file can be obtained
by compiling the example c file (embedded in the test)
with a conforming compiler such as gcc, clang or icc and then
printing the exported symbols (e.g., with nm+awk+sort).

(The implementation currently reserves two new VT_ flags.
If anyone can provide an implementation without reserving
two extra flags, please replace mine.)
2019-06-11 16:29:24 +02:00
matthias
cf3d23741f add tests for cleanup loop
- Also fix some gcc warning
2019-05-03 12:32:55 +02:00
Michael Matz
d30bc6d00a _Static_assert must be followed by semicolon
as per the C11 grammar.
2019-05-03 00:22:35 +02:00
matthias gatto
e371642e6b _Static_assert test 2019-04-28 08:27:33 +02:00
Michael Matz
85483f321d Add 103_implicit_memmove testcase
which checks that a declaration after TCC implicitely declares
an internally used function (memmove here) doesn't create any problem.
2019-04-18 03:42:23 +02:00
Michael Matz
105107124d Make 102_alignas independend of architecture
alignment of double is of course depending on the target,
so the .expect file was arch dependend.  Fix this by simply doing
some comparison tests.
2019-04-11 00:37:07 +02:00
Michael Matz
0344c0b6a0 Fix more struct inits
anonymous struct members were somewhat broken as the testcase
demonstrates.  The reason is the jumping through hoops to fiddle
with the offsets I once introduced to avoid having to track
a cumulative offset.  That's now not necessary anymore and actively
harmful, doing the obvious thing is now better.
2019-04-11 00:30:41 +02:00
Michael Matz
94846d3eef Some types testcases
during some rework I tripped over some more obscure but valid declarators.
Let's not loose them.
2019-04-09 04:39:38 +02:00
Michael Matz
ce4aea2478 Fix last commit's expected output
I forgot to regenerate the expected output of 102_alignas.c
just before committing and pushing :-/  This rectifies that.
2019-04-09 03:58:17 +02:00
Michael Matz
38a6aba468 Fix _Alignas
* don't accept _Alignas as type qualifier (after pointer '*').
* accept type-names within _Alignas
* add testcases
2019-04-08 22:06:51 +02:00
Michael Matz
2a417b50ee Detect invalid VLA decls
see testcase, when the inner array dimension of multi-dimensional
VLAs isn't given TCC was generating invalid vstack accesses.
Those are actually invalid, so just diagnose them.
2019-04-07 04:09:25 +02:00
Michael Matz
5ac2a26666 Don't endlessly recurse on invalid nested typedefs
see testcase.
2019-04-07 03:15:05 +02:00
Michael Matz
1fd3709379 Fix local extern vardecl
see testcases.  A local 'extern int i' declaration needs to
refer to the global declaration, not to a local one it might
be shadowing.  Doesn't seem to happen in the wild very often as
this was broken forever.
2019-03-18 05:53:03 +01:00
Michael Matz
e6980f6cc7 Detect more invalid initializers
in presence of invalid source code we can't rely on the
next token to determine if we have or haven't already parsed
an initializer element, we really have to track it in some separate
state; it's a flag, so merge it with the other two we have (size_only
and first).  Also add some syntax checks for situations which
formerly lead to vstack leaks, see the added testcases.
2019-03-18 03:31:11 +01:00
Michael Matz
4b46e0ec63 Handle corner case for abstract decls
sometimes abstract decls in parameter lists left the returned name
uninitialized potentially leading to segfaults, like in

  int f(int ()) {
    return 0;
  }

Deal with this.
2019-03-12 17:27:15 +01:00
Michael Matz
ef0397cf3d Fix crash on invalid code
like on 'enum myenum { L = -1 } L;'.  It's a bit tedious as
there are two paths (for global vs local symbols), and because
the scope and enum_val share same storage.
2019-03-08 17:58:25 +01:00
Michael Matz
08e22d8ad2 More cleanup tests
test3 wasn't working originally.
2019-01-28 05:54:19 +01:00
matthias
de92fbee7e add a cleanup test that use a lot of scope 2019-01-23 17:21:14 +01:00
matthias
ff38d90d5d Add attribute cleanup test 2019-01-23 17:21:14 +01:00
Matthias Gatto
2b94c0c3b1 Revert "allow c11 feature only when -std=c11 is use"
This reverts commit 756988e8f9.
2019-01-11 10:35:44 +01:00
matthias gatto
756988e8f9 allow c11 feature only when -std=c11 is use 2019-01-10 23:42:45 +01:00
Michael Matz
3e007193a2 Fix more attribute placements
when parsing the type in this cast:
  (int (__attribute__(X) *)(int))foo
we ignored the attribute, which matters if it's e.g. a 'stdcall'
attribute on the function pointer.  Only this particular placement
was misparsed.  Putting the attribute after the '*' or outside the inner
parens worked.  This idiom seems to be used on SQLite, perhaps this
fixes a compilation problem on win32 with that.
2018-12-31 22:00:31 +01:00
Christian Jullien
325241c0de zfunc works again on ARM after Pursuer fix 2018-12-22 19:14:22 +01:00
Christian Jullien
adfcf3b1dd Temporary remove zfunc test on ARM which generates a relocation error. Waiting for a fix 2018-12-20 08:44:47 +01:00
Michael Matz
c4787e3626 Fix type completion for array types as well
like qualifier merging the array sizes are merged as well
for the operands of ?:, and they must not statically influence
the types of decls.

Also fix some style problems, spaces aren't stinky :)
2018-11-30 23:43:30 +01:00
Petr Skocik
f7779efe58 Fix incorrect one-sided void handling in ?:
Also make the case when one side in ?: is a ptr
and the other is neither a ptr nor a null-ptr constant
fail cleanly instead of segfaulting.
2018-11-29 13:40:48 +01:00
Petr Skocik
49dfb5755a Make fn designators in ?: decay to ptrs
This
    _Generic((__typeof(1?f:f)*){0}, void (**)(void): (void)0);
should compile like it does in gcc and clang.
2018-11-29 12:43:01 +01:00