Commit Graph

3183 Commits

Author SHA1 Message Date
Michael Matz
d7f2775af8 Fix endless recursion due to type scoping
this change fixes building of invalid types.  The inner scope
struct P is return type of the forward decl foobar.  The outer scope
foobar() call implicitely declares that function again, with int
return type; overall this leads to access within the sym free list,
effectively building up a type directly referring to itself, leading
to endless recursion later.  The testcase is:

void n(void)
{
    {
      struct P {
          int __val;
      };
      struct P foobar(); // 1
    }
  foobar();  // 2
}

I've not included it in tests2 for now, because tcc accepts this.
Ideally we would like to reject it (as 'int foobar();' is incompatible
with the earlier decl).  clang also accepts it, but only because it's
not handling (1) above as an implicit decl of foobar (it warns, and
with -pedantic also warns about the type incompatiblity).  GCC rejects
this.

Implementing that in tcc requires some surgery, as we need to differ
between these cases:

  {  struct P foo(int); // 1
     foo();        // no implicit decl, call to foo from 1
  }

and

  { { struct P foo(int); // 2 }
    foo();         // implicit decl, _incompatible_ with 2
  }
2021-02-13 03:29:43 +01:00
Danny Milosavljevic
24c94fff09
arm-asm: Add vcvt 2021-02-13 01:03:41 +01:00
Danny Milosavljevic
f1fb23a661
arm-asm: Update comment 2021-02-13 01:03:39 +01:00
Michael Matz
30814dfacf Don't use stale section data pointers
put_elf_reloca might reallocate the section into which we point,
so don't remember the pointer just the offset.
2021-02-13 00:37:12 +01:00
Michael Matz
468e59206b Clear vtop.sym if saving on stack
normally the sym slot is meaningful only with VT_SYM.  But we also
use it when mentioning a decl for inline asms with register vars,
conditional on being a VT_LOCAL entry.  So when generating VT_LOCAL we
need to reset .sym as it might contain stale entries from the cmp_op
fields.
2021-02-13 00:24:29 +01:00
Michael Matz
ce8814cdd6 Avoid array overflow
with fuzzed source code we might run into this with idx out of bounds.
We're going to error out on this later, but let's not access
out-of-bounds elements.
2021-02-12 23:46:21 +01:00
Michael Matz
c4ae326a1d Revert "Long double Constant problem"
This reverts commit 405aef9155.
It doesn't compile (init_putv has no 'f1') and isn't necessary with a
compiler doing proper value initialization.
2021-02-12 22:52:05 +01:00
ayush-varshney
405aef9155 Long double Constant problem 2021-02-11 08:49:58 +01:00
Michael Matz
fbef90a703 Fix a VLA problem
see testcase, reduced example of a situation reported by
Kyryl Melekhin in https://github.com/kyx0r/neatvi/ .
Problem is that setting up the VLA sp-save in a scope that isn't
entered at runtime leaves traces of it in outer scopes that then
try to restore the stack pointer from uninitialized slots.
2021-02-03 04:30:11 +01:00
Danny Milosavljevic
d6f2d58158
Relicensing TinyCC 2021-02-02 14:07:43 +01:00
Riccardo Schirone
ad16628c9e Make sure to escape paths in generated make dependencies
If spaces are not escaped when generating the make dependencies file,
then if one of the dependencies has a space it would be interpreted as
two separate targets by Make, instead of just one.
2021-01-30 00:51:15 +01:00
Danny Milosavljevic
2ac8568503
arm-asm: Support immediate values without "#" (Unified Assembly Language) 2021-01-28 16:32:31 +01:00
Dmitry Selyutin
458457590d stdatomic: fix atomic_init parameters 2021-01-28 00:13:53 +03:00
Dmitry Selyutin
9d862be1e7 stdatomic: fix is_memory_model check 2021-01-28 00:13:07 +03:00
herman ten brugge
1c255baad5 test coverage update
Add myself to RELICENSING file
    Use locking when writing tcov file
    Fixed sometimes last line of function not shown
    Merge tcc_tcov_add_file and tcc_add_tcov
    Allow absolute file names
    Count case labels with no code better
2021-01-27 13:27:10 +01:00
Dmitry Selyutin
65773a5300 stdatomic: c11 prefix; migrate to models macros 2021-01-27 13:33:32 +03:00
Dmitry Selyutin
5053fd03a7 stdatomic: memory models as macros 2021-01-27 13:26:48 +03:00
Dmitry Selyutin
02ea864ad2 stdatomic: deplusification; LLVM notice 2021-01-27 13:25:12 +03:00
Dmitry Selyutin
f2e7742aea stdatomic: stdatomic.h header 2021-01-27 00:48:46 +03:00
Dmitry Selyutin
719a6b3a16 stdatomic: emit function calls 2021-01-26 22:37:44 +03:00
Dmitry Selyutin
a110287c31 stdatomic: atomic builtins parsing support 2021-01-26 22:37:44 +03:00
grischka
557b4a1f6d configure chmod 755 etc.
lib/tcov.c:
- can't be cross-compiled (needs stdio.h)
- can be included in libtcc1.a

Reason why bt-xxx.o/bcheck.o are linked separatly is because we
don't want then to linked into exe's and dlls at the same time.
2021-01-26 18:44:37 +01:00
Danny Milosavljevic
25628cffe5
arm-asm: Add vmsr, vmrs 2021-01-26 14:25:39 +01:00
Danny Milosavljevic
1c9d999114 arm-asm: Implement "vmov.f32 Sn, Rd", "vmov.f32 Rd, Sn", "vmov.f64 Dm, Rd, Rn", "vmov.f64 Rd, Rn, Dm" 2021-01-26 03:31:33 +01:00
Danny Milosavljevic
90343eba3a arm-asm: Mostly factor out VFP register reference parsing to parse_operand 2021-01-26 03:24:09 +01:00
Danny Milosavljevic
0416594071 arm-asm: Add vmov 2021-01-25 21:56:52 +01:00
Danny Milosavljevic
b82e52a497 arm-asm: Add vmla, vmls, vnmls, vnmla, vmul, vnmul, vadd, vsub, vdiv, vneg, vabs, vsqrt, vcmp, vcmpe 2021-01-25 21:56:52 +01:00
Danny Milosavljevic
104037a4c5
arm-asm: Raise error if user tries to use a shift instruction with an immediate source operand 2021-01-25 00:54:01 +01:00
grischka
1ed4b6ba1a debug_modes, re-unalign, cleanups
tccgen.c: debug_modes
- don't waste debug function calls during normal execution.
libtcc.c:
- mem_debug: no C99 features in tcc please, for example
  ({compound expressions}): do not use.
tccgen.c: struct_layout:
- unaligned access is completely ok for most targets.
- Moreover the patch was triggering single byte mode even
  for normal aligned access (as with tcc's SymAttr)

static Sym label: don't do this

arm-gen.c:
- use some #ifdefs to explain some code
tccpp.c:
- cleanup UCN chars
libtcc.c:
- replace openbsd library search
configure:
- cleanup strip fallouts
tccgen.c:
- expr_cond(): remove an exotic optimization that eventually
  got fixed to do the contrary by a gv(RC_InT)
- pop_local_syms(): remove some args
- init_putv() : use write##le functions to avoid cross-compiler
  unaligned access
- __bt_init(): remove unused param 'mode'
2021-01-24 18:00:33 +01:00
herman ten brugge
5043268cb1 Fix unaligned access arm (openbsd)
libtcc.c:
Fix unaligned load/store from magic3

tccgen.c:
For packed struct allways use single byte code
If field does not start at at align check it
Align stack correctly with vla
2021-01-24 11:28:26 +01:00
herman ten brugge
38eaf9b3a7 Fix compiler warnings utf8 code 2021-01-23 19:21:33 +01:00
herman ten brugge
b40a88ea46 Use arm assembler in lib dir 2021-01-23 19:08:59 +01:00
herman ten brugge
bc6c0c34c1 implement test coverage
I have implemented the -ftest-coverage option. It works a bit different
from the gcc version. It output .tcov text file which looks almost the
same as a gcov file after a executable/so file is run.

Add lib/tcov.c file
Modify Makefiles to compile/install it
Add -ftest-coverage option in tcc.c/tcc.h/tcc-doc.texi
Add code to tccelf.c/tccgen.c/tccpe.c
Add gen_increment_tcov to tcc.h/*gen.c

unrelated changes:
Add sigemptyset in tccrun.c
Fix riscv64-gen.c tok_alloc label size
2021-01-23 18:17:38 +01:00
Danny Milosavljevic
66de1550ab
arm-asm: Add vpush, vpop, vldm, vldmia, vldmdb, vstm, vstmia, vstmdb 2021-01-23 14:57:33 +01:00
Danny Milosavljevic
e350058532
arm-asm: Add svc 2021-01-23 14:20:06 +01:00
Danny Milosavljevic
2e87eb18ab
arm-asm: Improve build with MSVC 2021-01-21 21:56:10 +01:00
Danny Milosavljevic
3fc55e15e8
arm-asm: Enable VFP when invoking GNU as for testing VFP instructions 2021-01-21 20:33:04 +01:00
Danny Milosavljevic
cdbb55396c
arm-asm: Add vldr, vstr
Also add s0...s31, d0...d15
2021-01-21 18:15:19 +01:00
Danny Milosavljevic
31dde11ad5
arm-asm: Add ldc2, ldc2l, stc2, stc2l 2021-01-21 16:42:31 +01:00
Danny Milosavljevic
7900a6bb61
arm-asm: Add ldc, ldcl, stc, stcl 2021-01-21 16:42:28 +01:00
Danny Milosavljevic
d1a6c4aefa
arm-asm: Add mcr, mrc 2021-01-21 16:42:23 +01:00
Danny Milosavljevic
a1dad7a9f7
arm-asm: Add cdp2
Also allow instructions without condition code in the first place
2021-01-21 16:42:20 +01:00
Danny Milosavljevic
036a7fe7d4
arm-asm: Add cdp
Also add p0...p15 (coprocessors), c0...c15 (coprocessor register aliases)
2021-01-21 16:42:16 +01:00
Christian Jullien
593bed9b52 Fix arm NetBSD cross compilation 2021-01-19 08:58:24 +01:00
Danny Milosavljevic
d60d2bb60e
arm-asm: Make "!" optional in asm_block_data_transfer_opcode 2021-01-18 18:58:08 +01:00
Petr Skocik
704c8163fd re-add accidentally deleted printf("\n"); to tests2/97*.c 2021-01-18 08:32:50 +01:00
Petr Skocik
ffb95c2e0c Better handling of UCNs in strings
As the standard requires, take 4 hex digits after the \u opener of a
Universal Character Name, or take 8 hex digits after \U, but reject
smaller counts and don't consume more (https://port70.net/~nsz/c/c11/n1570.html#6.4.3,
https://port70.net/~nsz/c/c99/n1256.html#6.4.3).

The unicode codepoint used to get truncated to 1 byte. Now it gets expanded into UTF-8,
matching gcc & clang behavior on Linux.

TODO: Universal character names should also be supported in identifiers,
as in, e.g., char \u010dau_sv\u011bte[]="čau_světe";
2021-01-18 00:49:24 +01:00
herman ten brugge
6b614c4deb OpenBSD: arm fix
Disable warning softfloat. OpenBSD works fine.
save/restore s0-s15 during memcpy call for structs
update configure script. Works now on raspberry pi/All BSD
Add eabi_mem.. functions in armeabi.c for OpenBSD
Fix fp register in tccrun.c for OpenBSD
2021-01-17 20:43:15 +01:00
Christian Jullien
debe8d013d Use $targetos instead of a second call to uname 2021-01-17 11:45:23 +01:00
Christian Jullien
a2987fef19 configure automatically detects correct arm configuration on NetBSD 2021-01-17 09:02:00 +00:00