Commit Graph

1753 Commits

Author SHA1 Message Date
Edmund Grimley Evans
992cbda8d0 tccgen.c: Recognise constant expressions with conditional operator.
tests/tests2/78_vla_label.c: Check that int a[1 ? 1 : 1] is not a VLA.
2015-11-20 00:24:46 +00:00
Edmund Grimley Evans
30c54c9d43 tccgen.c: In parse_btype, handle typedef types with added type qualifiers.
In a case like

    typedef int T[1];
    const T x;

we must make a copy of the typedef type so that we can add the type
qualifiers to it.

The following code used to give

error: incompatible types for redefinition of 'f'

    typedef int T[1];
    void f(const int [1]);
    void f(const T);
2015-11-19 23:45:33 +00:00
Edmund Grimley Evans
58a34d22c9 tccgen.c: Improvements to type_to_str (only used for error messages).
1. Handle array types.
2. Print the type qualifiers of pointers.
2015-11-19 23:35:36 +00:00
Edmund Grimley Evans
ba99a70cd8 Trivial changes to avoid some compiler warnings. 2015-11-19 18:26:47 +00:00
Edmund Grimley Evans
553242c18a Replace pointer casts with calls to (read|write)(16|32|64)le.
This stops UBSan from giving runtime misaligned address errors
and might eventually allow building on a non-little-endian host.
2015-11-19 18:21:14 +00:00
Edmund Grimley Evans
5d496b1695 tccgen.c: Avoid undefined behaviour in constant propagation. 2015-11-17 19:34:31 +00:00
Edmund Grimley Evans
569fba6db9 Merge the integer members of union CValue into "uint64_t i". 2015-11-17 19:09:35 +00:00
Edmund Grimley Evans
3712c958f4 tests/tests2/79_vla_continue.c: Fix off-by-one error. 2015-11-13 21:49:29 +00:00
Edmund Grimley Evans
c39bc9caa7 libtcc.c: Completely replace tcc_normalize_inc_dirs. 2015-11-11 21:18:01 +00:00
Edmund Grimley Evans
a7334f791d arm64-gen.c: Avoid some cases of undefined behaviour.
Also make some functions more portable.
2015-11-09 23:06:05 +00:00
Edmund Grimley Evans
c52128c581 tccelf.c: Avoid two trivial instances of undefined behaviour. 2015-11-09 22:57:58 +00:00
Avi Halachmi (:avih)
951c23f257 win: include dirs: add some docs, minor refactor 2015-11-08 16:28:00 +02:00
seyko
37e815eee1 lib/Makefile: filter-out -b flag from XFLAGS
to build tcc with bound checking
    ./configure --cc=tcc --extra-cflags-b
2015-11-08 12:26:17 +03:00
seyko
763dd22b35 fix tcc_mormalize_inc_dirs naming 2015-11-08 11:42:56 +03:00
Avi Halachmi (:avih)
ec67dc482f win: fix incorrect directory detection
Allow other flags too...
2015-11-08 04:33:30 +02:00
Avi Halachmi (:avih)
acbab220c8 win: fix dir comparison during include dirs processing
Use native Windows API via wrapper with stat-like API.
2015-11-08 03:56:25 +02:00
Avi Halachmi (:avih)
9d33388b29 win: libm: add implementation for round/fmin/fmax and variants
round and fmin/fmax are relatively commonly used functions but were not
implemented anywhere in the tcc Windows distribution package. Newer mingw(64)
math.h stil doesn't include these implementations.

Add C implementations for these functions and place it as inline functions at
win32/include/tcc/tcc_libm.h - which is already included from math.h .

The code is mostly taken from musl-libc rs-1.0 (MIT) [*],

musl-libc: http://git.musl-libc.org/cgit/musl/tree/src/math?h=rs-1.0
license:   http://git.musl-libc.org/cgit/musl/tree/COPYRIGHT?h=rs-1.0

Potential enhancements:
- Check how many useful libm implementations are still missing and consider
  adding them (some of them already work via the MS runtime).
- Consider putting libm implementations in an actual libm.a file, or add a dummy
  one such that build processes which try to link with libm will not fail.
2015-11-07 22:31:57 +02:00
Avi Halachmi (:avih)
9c52ba48b3 win: math.h: fix fpclassify/signbit/etc - use C instead of broken asm
The asm code cannot currently be used with tcc since tcc doesn't support 't'
constraint.

Use inline C implementation instead, place it win32/include/tcc/tcc_libm.h, and
include it from win32/include/math.h.

Since fpclassify now works, it also fixes few other macros which depend on it.
Implicitly fixed: isfinite, isinf, isnan, isnormal.

The implementations were taken from musl-libc rs-1.0 (MIT license).

musl-libc: http://git.musl-libc.org/cgit/musl/tree/src/math?h=rs-1.0
license:   http://git.musl-libc.org/cgit/musl/tree/COPYRIGHT?h=rs-1.0
2015-11-07 22:18:46 +02:00
Avi Halachmi (:avih)
6e261a107c win: math.h: isnan: use macro, similar to others (still broken)
It was broken due to tcc not able to compile asm with 't' constraint, and it's
still broken because fpclassify on which it now depends has the same issue. Next
commit will fix this.
2015-11-07 22:17:21 +02:00
Avi Halachmi (:avih)
7307a6a3cb Revert "win32/include/math.h: remoing a "t" modifier usage"
This reverts commit 45bc505968.

The new asm code did not work as expected. Coordinated with seiko.
2015-11-07 21:30:56 +02:00
seyko
8fc9c79705 TOK_INCLUDE: fix for the "normalize inc dirs"
A case for the absolute path: prevent an error after openening
2015-11-06 02:50:36 +03:00
seyko
7cb921a44b TOK_INCLUDE: streamline
goto removed
2015-11-06 02:40:14 +03:00
Edmund Grimley Evans
eb00777309 tcctok.h: Put TOK_memmove in the correct places (I hope).
This should have been part of b051549. Someone should test on ARM.
2015-11-05 19:37:04 +00:00
Edmund Grimley Evans
7f0b798418 tcctok.h: Revert 41408f2, which moved TOK_memmove. 2015-11-05 19:33:46 +00:00
seyko
97916c9d04 tcc.h: remove CONFIG_TCCBOOT part
curremtly no one will try to compile a linux kernel
    from the boot loader. With current tcc it is not
    possible w/o additional tuning.
2015-11-05 20:30:51 +03:00
seyko
41408f2104 fix for the "tccgen.c: Use memmove for struct assignment"
./configure --enable-cross
    make
    tcc -o i386-tcc tcc.c
    tcc -o x86_64-tcc tcc.c
    tcc -o i386-win-tcc tcc.c
    In file included from tcc.c:22:
    In file included from libtcc.c:39:
    tccgen.c:2580: error: 'TOK_memmove' undeclared
2015-11-05 20:24:04 +03:00
seyko
0ad87a094c fix for the previous commit
a cross-compilation from unix to win32 need a "sys/stat.h"
    include file
2015-11-05 20:14:42 +03:00
seyko
a6276b7a78 normalize inc dirs, symplify include_next
include dirs are prepared as in gcc
    - for each duplicate path keep just the first one
    - remove each include_path that exists in sysinclude_paths

    include_next streamlined by introducing inc_path_index
    in the BufferedFile
2015-11-05 19:52:49 +03:00
seyko
45bc505968 win32/include/math.h: remoing a "t" modifier usage
replaced by loading a float argument from memory and
    using the "m" modifier
2015-11-05 14:27:41 +03:00
Edmund Grimley Evans
f7dd3d49cc lib/libtcc1.c: Replace "long" with "unsigned int" in union float_long. 2015-11-04 23:22:00 +00:00
Edmund Grimley Evans
24308fd292 tccpp.c: In TOK_GET, add comment warning about illegal cast.
Also, in tok_str_add2, use memcpy instead of the illegal cast.

Unfortunately, I can't see an easy way of fixing the bug.
2015-11-04 20:27:54 +00:00
Edmund Grimley Evans
20f0c179da tccpp.c: Define and use tok_last for checking if last token is space. 2015-11-04 20:25:26 +00:00
Edmund Grimley Evans
b051549f2e tccgen.c: Use memmove for struct assignment: dest and src may be equal. 2015-11-04 20:23:17 +00:00
Edmund Grimley Evans
8eab556ac5 tccgen.c: Fix memory leak involving asm_label. 2015-11-04 20:22:30 +00:00
Edmund Grimley Evans
9bf0e57509 tests/tcctest.c: Fix up format strings. 2015-11-04 20:20:26 +00:00
Edmund Grimley Evans
f4082851ea Enable variable-length arrays on arm64.
arm64-gen.c: Implement gen_vla_sp_save, gen_vla_sp_restore, gen_vla_alloc.
tests/Makefile: Run vla_test on arm64.
2015-10-31 11:04:52 +00:00
seyko
35e715a1e3 defined twice: revert
An error message is changed to suggest -fcommon
2015-10-29 17:10:04 +03:00
seyko
c07785a1ea comment out tcc_error_noabort("'%s' defined twice"...
gcc-3.4.6 don't give such error by default
    example file1
	char __version_303_xxxxxxxx;
	void func1() {}
    example file2
	char __version_303_xxxxxxxx;
	void func2() {}
	int main() { return 0; }
2015-10-25 00:41:17 +03:00
seyko
12f94f2770 include/stddef.h: define NULL only if undefined 2015-10-25 00:19:12 +03:00
seyko
f3ce1be333 tcc help output for the -xc -xa - options 2015-10-24 23:39:17 +03:00
seyko
003c532bf3 fix for the #include_next, v4 (final)
This version looks rigth. Comparing to the original
    algorithm:

    1) Loop breaking. We remember a start point after wich
    we can try next path. Do not search include stack after
    this.

    2) But compare next file patch with the start point.
    Skip if it the same. Remove "./" before comparing.

    PS: a problems with compaling a coreutils-8.24.51-8802e
    remain. There are errors messages like:
    src/chgrp
        src/chown-core.c:42: multiple definition of `make_timespec'
        src/chgrp.c:42: first defined here
    A problem is in the lib/config.h
        #define _GL_INLINE_ extern inline // gcc
        #define _GL_INLINE_ inline        // tcc

    A long description from the lib/config.h
    * suppress extern inline with HP-UX cc, as it appears to be broken
    * suppress extern inline with Sun C in standards-conformance mode
    * suppress extern inline on configurations that mistakenly use
      'static inline' to implement functions or macros in standard
      C headers like <ctype.h>.

    GCC and Clang are excluded from this list. Why not tcc?
2015-10-20 07:32:53 +03:00
seyko
ad1c01f96c fix for the #include_next, v3
don't give an error and simply ingnore directive
  if we detect a loop of the #include_next.

  With this aproach coreutils-8.24.51-8802e
  compiles, but with errors:
  	lib/libcoreutils.a: error: 'xnmalloc' defined twice
	lib/libcoreutils.a: error: 'xnrealloc' defined twice
2015-10-19 17:55:26 +03:00
seyko
6b9490b6ff fix for the #include_next, v2
A more correct fix. This one don't break old logic.
    But if include file is not found, we try to search
    again with the new compare rule.

    A description of the problem:
    http://permalink.gmane.org/gmane.comp.compilers.tinycc.devel/2769
2015-10-17 15:48:10 +03:00
seyko
ad524bb6c7 reverse a previous patch
a next version of the patch will follow
2015-10-17 15:32:33 +03:00
seyko
285292992f fix for the #include_next
skip include file only if include_file_name=current_file_name
2015-10-17 14:45:51 +03:00
seyko
c3975cf27c parsing "..." sequence
don't panic with
	error: '.' expected
    if there is only two '.' chars. Return tok='.' in such case.
    An asm code to test:
	jz	do_move0	# .. then we have a normal low
				# .. or else we have a high
2015-10-17 13:54:58 +03:00
Edmund Grimley Evans
f0b7566181 tccelf.c: Reset sym after call to build_got.
The call to build_got can cause symtab_section->data to be reallocated
(build_got -> add_elf_sym -> put_elf_sym -> section_ptr_add ->
section_realloc -> tcc_realloc). This is not obvious on a cursory
inspection, but fortunately Valgrind spotted it immediately.
Are there other, similar bugs that Valgrind did not detect?
2015-10-16 20:33:41 +01:00
Edmund Grimley Evans
743684fe39 tccpp.c: Avoid infinite loop on: printf '/**' | ./tcc - 2015-10-15 19:02:58 +01:00
Edmund Grimley Evans
c899659d39 tccgen.c: Remove undefined shift of negative signed value. 2015-10-15 19:02:57 +01:00
Edmund Grimley Evans
eafd7a7d3b Correct prototype: void __clear_cache(void *, void *). 2015-10-15 19:02:54 +01:00