Commit Graph

1520 Commits (2437ccdc768b1a4fde3255b2090e180b74ab198f)
 

Author SHA1 Message Date
seyko 2437ccdc76 A partial reverse for commit eda2c756ed
Author: Thomas Preud'homme <robotux@celest.fr>
	Date:   Tue Dec 31 23:51:20 2013 +0800

	Move logic for if (int value) to tccgen.c
	Move the logic to do a test of an integer value (ex if (0)) out of
	arch-specific code to tccgen.c to avoid code duplication. This also
        fixes test of long long value which was only testing the bottom half of
	such values on 32 bits architectures.

I don't understand why if () in gtst(i) was removed.
This patch allows to compile a linux kernel v.2.4.26
W/o this patch a tcc simply crashes.
2015-03-03 15:51:09 +03:00
seyko c45a8695eb A reverse of the commit 14745bdeb because of the problems while compiling linux 2.4.26
A test program:
    ///////////
    typedef unsigned int __u32;
    static inline const __u32 __fswab32(__u32 x)
    {
	return ({ __u32 __tmp = (x) ; ___swab32(__tmp); });
    }
    void func()
    {
	int aaa = 1;
	int snd_wnd = 2;
	int TCP_FLAG_ACK = 3;
	int pred_flags = (__builtin_constant_p((__u32)
	    (((aaa << 26) |
	    (__builtin_constant_p((__u32)((TCP_FLAG_ACK))) ?
		({ __u32 __x = (((TCP_FLAG_ACK))); ((__u32)( (((__u32)(__x) & (__u32)0x000000ffUL) << 24) | (((__u32)(__x) & (__u32)0x0000ff00UL) << 8) | (((__u32)(__x) & (__u32)0x00ff0000UL) >> 8) | (((__u32)(__x) & (__u32)0xff000000UL) >> 24) )); }) : __fswab32(((TCP_FLAG_ACK)))) | snd_wnd))) ? ({ __u32 __x = ((((aaa << 26) | (__builtin_constant_p((__u32)((TCP_FLAG_ACK))) ? ({ __u32 __x = (((TCP_FLAG_ACK))); ((__u32)( (((__u32)(__x) & (__u32)0x000000ffUL) << 24) | (((__u32)(__x) & (__u32)0x0000ff00UL) << 8) | (((__u32)(__x) & (__u32)0x00ff0000UL) >> 8) | (((__u32)(__x) & (__u32)0xff000000UL) >> 24) )); }) : __fswab32(((TCP_FLAG_ACK)))) | snd_wnd))); ((__u32)( (((__u32)(__x) & (__u32)0x000000ffUL) << 24) | (((__u32)(__x) & (__u32)0x0000ff00UL) << 8) | (((__u32)(__x) & (__u32)0x00ff0000UL) >> 8) | (((__u32)(__x) & (__u32)0xff000000UL) >> 24) )); }) : __fswab32((((aaa << 26) | (__builtin_constant_p((__u32)((TCP_FLAG_ACK))) ? ({ __u32 __x = (((TCP_FLAG_ACK))); ((__u32)( (((__u32)(__x) & (__u32)0x000000ffUL) << 24) | (((__u32)(__x) & (__u32)0x0000ff00UL) << 8) | (((__u32)(__x) & (__u32)0x00ff0000UL) >> 8) | (((__u32)(__x) & (__u32)0xff000000UL) >> 24) )); })
		: __fswab32(((TCP_FLAG_ACK)))) | snd_wnd))));
    }
    ////////////
error: ';' expected (got "(")
2015-03-03 15:44:29 +03:00
seyko 6fd4e5bace a void to void cast.
Allow tcc to compile the following program
    ///////
	void func1() {}
	void func2() {
	  return func1();
	}
    //////
gcc accepts this program
2015-03-03 15:39:57 +03:00
seyko 09feeca5df a statement expressions with a pointer return type
A test program:
    //////////////
    int main()
    {
	void *p = ({ 0 ; ((void *)1); });
    }
    /////////////
Porblem is introduced in a commit a80acab: Display error on statement expressions with complex return type
This error is exposed when compiling a linux 2.4.26. tcc 0.9.23 can sucessfully compile
this version of the linux.
2015-03-03 15:29:14 +03:00
seyko 1a1e9548fb iitialisation of the empty struct
Current tcc don't understand an initialization of the empty struct
This problem was found trying to compile a linux kernel 2.4.26
which can be compiled by tcc 0.9.23

  A test program:
  ////////////////////
  // ./tcc -c test_3.c
  // test_3.c:31: error: too many field init
  #undef __GNUC__
  #undef __GNUC_MINOR__
  #define __GNUC__  2
  #define __GNUC_MINOR__ 95
  typedef struct { } rwlock_t;
  struct fs_struct {
   int count;
   rwlock_t lock;
   int umask;
  };
  #define INIT_FS { \
	1, \
	RW_LOCK_UNLOCKED, \
	0022, \
  }
  #if (__GNUC__ > 2 || __GNUC_MINOR__ > 91)
    typedef struct { } rwlock_t;
    #define RW_LOCK_UNLOCKED (rwlock_t) { }
  #else
    typedef struct { int gcc_is_buggy; } rwlock_t;
    #define RW_LOCK_UNLOCKED (rwlock_t) { 0 }
  #endif
  static struct fs_struct init_fs = INIT_FS;
  // static struct fs_struct init_fs = { { (1) }, (rwlock_t) { 0 }, 0022, };
  //                                                           ^ with this all Ok
  // static struct fs_struct init_fs = { { (1) }, (rwlock_t) { }, 0022, };
  //                                                          ^ current tcc don't understand, but tcc 0.9.23 can
  int main()
  {
    return 0;
  }
  ////////////////////
  A regression is detected after a patch 69fdb57edd
  ////////////////////
  // A test for patch 69fdb57edd
  // Author: grischka <grischka>
  // Date:   Wed Jun 17 02:09:07 2009 +0200
  //     unions: initzialize only one field
  //         struct {
  //           union {
  //             int a,b;
  //           };
  //           int c;
  //         } sss = { 1,2 };
  //     This had previously assigned 1,2 to a,b and 0 to c which is wrong.
  //
  // Expected: sss.a=1 sss.b=1 sss.c=2
  int main()
  {
    struct {
      union {
        int a,b;
      };
      int c;
    } sss = { 1, 2 };

    printf ("sss.a=%d sss.b=%d sss.c=%d\n", sss.a, sss.b, sss.c);
    return 0;
  }
  ////////////////////
2015-03-03 15:15:48 +03:00
seyko bbf8221ec3 tcc don't understand am extern array of structs.
A regression was found trying to compile a linux kernel 2.4.26
  which can be compiled by tcc 0.9.23

    ///////////////////
    #include <stdio.h>

    // test for a bug:
    // compiler don't understand am extern array of structs
    // $ tcc test_1.c
    // test_1.c:8: error: unknown struct/union/enum

    extern struct FILE std_files[4];

    int main()
    {
	return 0;
    }
    //////////////////

  tcc-current
  /* enum/struct/union declaration. u is either VT_ENUM or VT_STRUCT */
  static void struct_decl(CType *type, int u, int tdef)
  ...
    if (tok != '{') {
        v = tok;
        next();
        /* struct already defined ? return it */
        if (v < TOK_IDENT)
            expect("struct/union/enum name");
        s = struct_find(v);
        if (s) {
            if (s->type.t != a)
                tcc_error("invalid type");
            goto do_decl;
        } else if (tok >= TOK_IDENT && !tdef)
            tcc_error("unknown struct/union/enum");
    } else {
        v = anon_sym++;
    }

  tcc-0.9.23 which don't have such error
  /* enum/struct/union declaration. u is either VT_ENUM or VT_STRUCT */
  static void struct_decl(CType *type, int u)
  ....
    if (tok != '{') {
        v = tok;
        next();
        /* struct already defined ? return it */
        if (v < TOK_IDENT)
            expect("struct/union/enum name");
        s = struct_find(v);
        if (s) {
            if (s->type.t != a)
                error("invalid type");
            goto do_decl;
        }
    } else {
        v = anon_sym++;
    }
2015-03-03 15:00:13 +03:00
seyko a429d40f06 tcc_free(table_ident) in preprocess_new() if table_ident != NULL 2015-03-03 14:54:46 +03:00
seyko e2a8fd4520 tcc_undefine_symbol(): free an alloced symbol 2015-03-03 14:50:41 +03:00
seyko 8d10c5788f Add a debug info when a #line directive is handled.
The problem was: a debug info for the file which contain a #line
directive (for example a preprocessed one) was wrong.
2015-03-03 14:46:44 +03:00
seyko 09d4e4f408 Revert a grischka patch: gdb refused to know "main"
It is a strange patch because before this commit a gdb is working well
and after this commit there is exactly the same problem on Linux:
gdb refuses to know "main"

    Author: grischka <grischka>
    Date:   Tue Feb 5 21:18:29 2013 +0100
    tccelf: fix debug section relocation
    With:
       tcc -g hello.c
       gdb a.out
         b main
    gdb refused to know "main" because of broken dwarf info.
2015-03-03 14:39:27 +03:00
seyko 252a151fc6 pp-many-files: don't drop a preprocessor defines when tcc going to preprocess a next file
in the same pass like
    tcc -E one.c two.c three.c -o combined.i
This will allow to speed up a compilation process by using a commamd like
    tcc -E *.c | tcc -o program.exe -xc -

It looks that multi-times initialization don't affect anything.
Only call to the free_defines(define_start) in tcc_preprocess()
is removed in assumption that free_defines(NULL) in
tcc_cleanup() will free all defines.
2015-03-03 14:31:47 +03:00
seyko b7b9f9f511 A gcc preprocessor option -dD added
With this option on a defines are included into the output
(inside comments). This will allow to debug a problems like:

    In file included from math.c:8:
    In file included from /usr/include/math.h:43:
    /usr/include/bits/nan.h:52: warning: NAN redefined
2015-03-03 14:25:57 +03:00
seyko 50cdccf3ef Added a gcc preprocessor options -P, -P1
tcc -E -P
  do not output a #line directive, a gcc compatible option

tcc -E -P1
  don't follow a gcc preprocessor style and do output a standard
  #line directive. In such case we don't lose a location info when
  we going to compile a resulting file wtith a compiler not
  understanding a gnu style line info.
2015-03-03 14:19:14 +03:00
seyko 40418f87c7 Move a line_ref variable from tcc_preprocess() function into struct BufferedFile.
This id needed for a right ouput in other places,
precisely to calculate a number of empty lines which are waiting to output.
2015-03-03 14:15:28 +03:00
seyko 5e3e321474 A preprocessor should Interpret an input line "# NUM FILENAME" as "#line NUM FILENAME"
A cpp from gcc do this.
A test case:
     tcc -E tccasm.c -o tccasm.i
     tcc -E tccasm.i -o tccasm.ii
After a patch the line numbers in tccasm.ii are the same
as in tccasm.i
2015-03-03 14:06:05 +03:00
Edmund Grimley Evans 1706d2254b arm64-gen.c: Improve generation of stack offsets. 2015-03-02 20:51:03 +00:00
Edmund Grimley Evans 1d41da9590 arm64-gen.c: Rename some functions and add comments. 2015-03-02 20:45:58 +00:00
Edmund Grimley Evans 86e8dcd5e2 arm64: Improve constant generation, with tests. 2015-03-02 20:39:28 +00:00
Edmund Grimley Evans 883fd365c7 arm64-gen.c: Better explanation of relocation choice. 2015-03-01 11:31:10 +00:00
Edmund Grimley Evans fc119f9840 73_arm64.c: Avoid taking address of return value. 2015-02-26 12:27:00 +00:00
Edmund Grimley Evans 8329facdfa Add 73_arm64 for testing some arm64 things, mostly PCS. 2015-02-25 22:51:41 +00:00
Edmund Grimley Evans a4d43618fb arm64-gen.c: In gen_va_arg, handle the remaining HFA cases. 2015-02-25 22:51:41 +00:00
Edmund Grimley Evans 36bb8994dd Relicensing TinyCC 2015-02-25 07:52:39 +00:00
Edmund Grimley Evans 97e08be344 tests/tcctest.c: Test COMPAT_TYPE(char *, signed char *). 2015-02-24 19:35:31 +00:00
Edmund Grimley Evans 40f7e11c53 tccgen.c: Make sure that gen_op always returns an rvalue.
Either this fix, or an alternative one, is required for arm64.
2015-02-23 22:51:10 +00:00
Michael Matz 6d055312a2 aarch64: Fix -run.
This adds some more support for properly transfering some
offsets over the different stages of a relocations life.
Still not at all psABI compliant and DSOs can't yet be generated.
But it runs the testsuite in qemu-arm64.
2015-02-23 22:51:10 +00:00
Edmund Grimley Evans b14ef0e24b Add arm64 (AArch64) as a target architecture. 2015-02-23 22:51:03 +00:00
Edmund Grimley Evans 738606dbd5 Use RELA relocations properly for R_DATA_PTR on x86_64.
libtcc.c: Add greloca, a generalisation of greloc that takes an addend.
tcc.h: Add greloca and put_elf_reloca.
tccelf.c: Add put_elf_reloca, a generalisation of put_elf_reloc.
tccgen.c: On x86_64, use greloca instead of greloc in init_putv.
2015-02-21 21:29:03 +00:00
Edmund Grimley Evans 86c850fc58 tcc-doc.texi: Explain VT_LLOCAL a bit better.
And delete the sentence about it being removed.
2015-02-20 23:29:21 +00:00
Edmund Grimley Evans ff3f9aa6ba Fix handling of case_reg in switch statement.
The back end functions gen_op(comparison) and gtst() might allocate
registers so case_reg should be left on the value stack while they
are called and set again afterwards.
2015-02-20 23:16:00 +00:00
Thomas Preud'homme a6c3ce6ec0 The "open a whisky and cut your finger open" patch
Make integer constant parsing C99 compliant
2015-02-18 07:01:03 +00:00
Reimar Döffinger ff783b94c7 Add support for .p2align asm directive.
Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
2015-01-20 08:49:49 +01:00
Reimar Döffinger fb6331e0fa Fix macro expansion of empty args.
Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
2015-01-18 22:00:10 +01:00
Reimar Döffinger a6149c6dbb Set CONFIG_MULTIARCHDIR for cross compilers.
Chances a cross-compiler will find a working crt*.o
in /usr/lib are more or less 0.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
2015-01-18 21:21:59 +01:00
Reimar Döffinger ae09558d71 Build also WinCE cross compiler when cross compilers enabled.
Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
2015-01-18 21:16:34 +01:00
seyko e260b03686 Allow tcc to understand a setob,... opcodes as alias to seto,...
PS: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20101122/112576.html
This is fix PR8686 for llvm: accepting a 'b' suffix at the end
of all the setcc instructions.
2015-01-06 22:59:19 +03:00
seyko c334b59142 Warn about a conflicting compile options spectified on the command line.
Try "tcc -E -c tccasm.c -o tccasm.o"
2015-01-06 22:19:45 +03:00
seyko b93179f3c0 .i as file extension
Add a ".i" extension as alias for ".c"
 GCC and file extensions:
 .i C source code which should not be preprocessed.

Before a patch:
 ./tcc -E tccasm.c -o tccasm.i
 ./tcc -c tccasm.i -o tccasm.o
 tccasm.i:1: error: unrecognized file type
2015-01-06 16:01:41 +03:00
seyko 524abd46b4 round() in test (24_math_library) fail because there are no defs included.
gcc complain but work right and tcc simply fail to compile right.
2015-01-05 18:23:32 +03:00
Carlos Montiers 77ef3b2929 crt1.c revision 2014-12-30 00:25:52 -03:00
Lee Duhem 5a76c5d2f3 Fix parsing of binary floating point number
* tccpp.c (parse_number): `shift' should be 1 while parsing binary
floating point number.
* tests/tests2/70_floating_point_literals.c: New test cases for
floating point number parsing.
2014-12-15 16:32:08 +08:00
Lee Duhem 20a5845a47 tcc.h (BufferedFile): Remove unnecessary static memory allocation
The memory needed by `buffer' will be allocated in `tcc_open_bf',
these is no need to allocate them in BufferedFile statically.
2014-12-11 10:04:22 +08:00
Lee Duhem f1703e2b2f libtcc.c (put_extern_sym2): Extend the scope of buf to match its use
After leaving the code block that `buf' is defined, `buf' will not
exist, so `name' will point to a variable that does not exist.
2014-12-11 10:04:22 +08:00
Lee Duhem 4bf3f6c965 .gitignore: Ignore Emacs temporary files 2014-12-11 10:04:22 +08:00
Lee Duhem 73e8f6b60a Makefile: Add rules to create tags and TAGS. 2014-11-28 23:25:05 +08:00
Lee Duhem 4ae462b668 .gitignore: Ignore generated files. 2014-11-28 23:24:55 +08:00
Carlos Montiers 9b14e8715a little optimization to crt1 2014-11-23 01:51:38 -03:00
Carlos Montiers f40b82295e __getmainargs compatibility checking success 2014-11-22 19:00:49 -03:00
James Buren 1e07ea71d3 win32: fix implicit function warning
This includes windows.h to fix a warning about
an implicit function usage of ExitProcess().
2014-11-03 16:17:15 -06:00
Matteo Cypriani 26b26f355f Filter-out warning about softfloat in tests2 2014-10-17 16:37:54 -04:00