Commit Graph

2421 Commits

Author SHA1 Message Date
Devin Hussey
9382a3ad58 C11 conformance: Add _Noreturn, stdnoreturn.h, and partial _Alignas support
_Noreturn, just like __attribute__((noreturn)), is ignored.
I also added stdnoreturn.h, in all its glorious uselessness.

_Alignas only works for integer expressions right now. In order
to comply, we need:
 - _Alignas(type) -> _Alignas(_Alignof(type)).
 - stdalign.h as soon as it is done.

Note: DR 444 is supported; it works on struct members.

Signed-off-by: Devin Hussey <husseydevin@gmail.com>
2019-03-20 15:03:27 -04: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
d72b877e45 Fix invalid memory access in preprocess_end
when an error is thrown macro_stack might point to
unwound local variables, we can't access them.
2019-03-15 13:17:58 +01:00
Vincent Lefevre
be7c870718 Fix va_end() definition: must be an expression of type void
Also added a test yielding a failure with the previous definition,
i.e. when using: (va_end(ap));

The test also checks potentially incorrect va_start() definition.
2019-03-14 15:39:52 +01:00
Vincent Lefevre
920f773a81 Fix "make -j test"
The clean-s rule must be run before the tests, not at the same time!
2019-03-14 14:59:27 +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
matthias
b082659f19 fix segv in "{,}" combound literal 2019-03-06 18:51:13 +01:00
Michael Matz
fef838db2d Fix relocs of unwanted sections
relocation sections to sections we don't want to handle lead
to segfaults, handle this situation (by ignoring the relocs
as well).
2019-03-04 16:53:24 +01:00
Michael Matz
749d19d70b Fix sub-int returns on x86-64 and i386
the ABIs (and other compilers) extend sub-int return values in the
caller.  TCC extends them in the callee.  For compatibility with
those other compilers we have extend them in the caller as well.
That introduces a useless double extension in pure TCC-compiled code,
but fixing that generally requires that the code generator of TCC would
understand sub-int types.  For the time being bite the bullet.
2019-02-10 18:27:41 +01:00
Michael Matz
5f737fb4d3 tidy code 2019-01-31 01:04:55 +01:00
Michael Matz
5c862a08b4 suppress code after continue as well
fix an oversight in code suppression
2019-01-31 00:37:49 +01:00
matthias
d27ea5155f remove incr/decr_local_scope functions 2019-01-29 21:32:38 +01:00
Michael Matz
08e22d8ad2 More cleanup tests
test3 wasn't working originally.
2019-01-28 05:54:19 +01:00
Michael Matz
4cc802a88e Tidy new support for cleanups
encode most things in Syms, do only as much work as necessary
(e.g. pending cleanups), don't track scopes in a large
structure (instead encode the scopes with cleanups directly
in the cleanups tree).  Removes ca. 120 lines of code.
2019-01-28 05:54:19 +01:00
Detlef Riekenberg
5d805a90e3 tcc.c: Fix outdated help info for the std option
the std option is no longer ignored

--
bye bye ... Detlef

Signed-off-by: Detlef Riekenberg <tcc.dev@web.de>
2019-01-27 17:32:11 +01:00
matthias
46145af4a1 remove C99 'for' loop initial declarations 2019-01-23 19:42:04 +01:00
matthias
5010023428 remove outdated comment 2019-01-23 17:21:14 +01:00
matthias
de92fbee7e add a cleanup test that use a lot of scope 2019-01-23 17:21:14 +01:00
matthias
26f0cf0708 Fix scope limit for cleanup attribute
old implementation use only a global static array for storing
ScopeTracker which have the advantage to be fast, but you can't
use cleanup in a function that have move than SCOPE_TCK_STORE_SIZE
scopes.

I don't want to use only dynarray_* as it would slow down tcc for
every functions, so I keep both stores.
2019-01-23 17:21:14 +01:00
matthias
ff38d90d5d Add attribute cleanup test 2019-01-23 17:21:14 +01:00
matthias
0d91ba749c Add gcc attribute cleanup support
The major difficulty was to handle cleanup when a goto happen
to do so, I've had a "ScopeTracker" struct.
I can't use local_scope because that would not work with code like below
as local_scope would be at the same level:

{
    char * __attribute__ ((cleanup(clean_function))) str = "hej";
    goto next;
}
{
    next:
}
2019-01-23 17:21:14 +01:00
Giovanni Mascellani
f6be0d483b
Fix read() usage in tccelf.c.
read() is allowed to short-read, and return less bytes then requested.
The caller must restart read() when this happens (and they want more
bytes).

This patch is still buggy, because errors are not always checked.
Still, less buggy than before.
2019-01-13 15:20:39 +01:00
Christian Jullien
acac38afb2 Add C99 compiliant iso646.h header 2019-01-13 10:24:50 +01:00
Michael Matz
45b8b0e57d Revert 337dc84b (other -static fix)
this should work now with 05f6aa1a.
2019-01-13 06:01:59 +01:00
Michael Matz
05f6aa1ade Fix -static linking with uClibc
symbols are local when defined and referred to from the executable.
Also, we need to relocate the .got section when this is a static link
(our static linking effectively generates code as if this were a dynamic
link with PLT and GOT, and then emulates the runtime loader).
2019-01-13 06:00:51 +01:00
Michael Matz
adbe794a46 Properly access sym_attrs
in corner cases the direct access to the sym_attrs[] array in the
backends is out of bounds and replacec garbage symindices into
the relocs.
2019-01-13 02:55:44 +01:00
Christian Jullien
d44d8cdf60 Add more STDC_ C11 compatible constants 2019-01-12 10:41:56 +01:00
Pursuer
ecb90de4cc FIX:Revert commit 3f05d88d5b
The function should to be saved to stack in some cases (fastcall on i386, struct argument on arm etc.). But I neglected. So I revert this commit.
2019-01-12 01:54:24 +08:00
Christian Jullien
8482f9e54b Add __STDC_xxx test features related to ISO/IEC C11 when -std=c11 is passed. 2019-01-11 14:26:17 +01:00
Petr Skocik
065a3b35fc Make stddef.h expose max_align_t with -std= >= c11 2019-01-11 11:17:49 +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
Christian Jullien
a3a291784a Add -std=c11 option which sets __STDC_VERSION__ to 201112L and allows to implement c11 features conditionally 2019-01-11 02:32:48 +08:00
Kurt Nalty
337dc84b57 Fixed -static linking on x86_64 Linux 2019-01-11 02:32:48 +08:00
Petr Skocik
51f6e52dd3 Support multiple __label__ declarations
Support multiple __label__ declarations at the beginning of a block
as long as they're contiguous.

gcc and clang accept:
    { __label__ a,b; __label__ c;  /*...*/ }
.
Tcc would fail it. This patch makes it accept it.

The patch:
-        if (tok == TOK_LABEL) {
+        while (tok == TOK_LABEL) {
2019-01-11 02:32:47 +08:00
Pursuer
3f05d88d5b optimize the generated code when save_reg is required (2)
In gfunc_call, regisger will be saved before gcall_or_jmp. The register
stored the function will be saved too, though in some generator the SValue
of this function will be immediately poped after gcall_or_jmp, and no need to be saved. So I modify some generator to avoid save redundant SValue before gcall_or_jmp.
2019-01-11 02:32:12 +08:00
Pursuer
b3b685d92a optimize the generated code when save_reg is required
Before this patch, save_reg can't reuse the temporary local variable
created before to save register. It may consume a lot of stack memory. this patch make save_reg reuse the temporary local variable.
2019-01-10 13:17:14 +08:00
Pursuer
0c313f491b Insert arm-xxx_FILES into Makefile to suport CROSS_TARGET and Remove duplicate function lexpand_nr 2019-01-09 02:06:26 +08:00
Petr Skocik
7369cfc490 Revert "Add max_align_t to stddef.h"
max_align_t is C11 not C99 and the name is not reserved by C99.

This reverts commit 7eceba178d.
2019-01-08 12:32:18 +01:00
Petr Skocik
7eceba178d Add max_align_t to stddef.h 2019-01-04 14:56:37 +01:00
Christian Jullien
f21b53b5ed Add winnls.h to allow SQLite compile ROOTB on Windows 2019-01-01 08:58:09 +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
general
bf09349f8e fix arm-gen.c -> gcall_or_jmp to VT_CONST 2018-12-22 19:48:56 +08:00
Theodore Dubois
82abfd75f3 Fix ELF interpreter of i386 musl target 2018-12-22 04:29:06 +00:00
Michael Matz
63f69c2bdd Disable -Wformat-truncation
this new gcc 8 warning triggers here, but is useless for our
purposes.
2018-12-21 01:03:38 +01:00
Michael Matz
f68a1f50fd Don't use C99 decls
we're consciously trying to write C90 compatible code, hence
no mixed declaration and code.
2018-12-21 01:03:05 +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