Commit Graph

212 Commits

Author SHA1 Message Date
jiang
d316836008 Let init_putz one-time generation.
At the same time, increase the GCC style warning
---------------------------------------------------------------------------
int main()
{
	int a[10] = {[5]=5};
	return 0;
}

Disassembly of section .text:

0000000000000000 <main>:
   0:	55                   	push   %rbp
   1:	48 89 e5             	mov    %rsp,%rbp
   4:	48 81 ec 30 00 00 00 	sub    $0x30,%rsp
   b:	b8 05 00 00 00       	mov    $0x5,%eax
  10:	89 45 ec             	mov    %eax,-0x14(%rbp)
  13:	48 b8 14 00 00 00 00 	movabs $0x14,%rax
  1a:	00 00 00
  1d:	49 89 c2             	mov    %rax,%r10
  20:	b8 00 00 00 00       	mov    $0x0,%eax
  25:	48 89 c6             	mov    %rax,%rsi
  28:	48 8d 45 d8          	lea    -0x28(%rbp),%rax
  2c:	48 89 c7             	mov    %rax,%rdi
  2f:	4c 89 d2             	mov    %r10,%rdx
  32:	b8 00 00 00 00       	mov    $0x0,%eax
  37:	e8 fc ff ff ff       	callq  38 <main+0x38>
  3c:	48 b8 10 00 00 00 00 	movabs $0x10,%rax
  43:	00 00 00
  46:	49 89 c2             	mov    %rax,%r10
  49:	b8 00 00 00 00       	mov    $0x0,%eax
  4e:	48 89 c6             	mov    %rax,%rsi
  51:	48 8d 45 f0          	lea    -0x10(%rbp),%rax
  55:	48 89 c7             	mov    %rax,%rdi
  58:	4c 89 d2             	mov    %r10,%rdx
  5b:	b8 00 00 00 00       	mov    $0x0,%eax
  60:	e8 fc ff ff ff       	callq  61 <main+0x61>
  65:	b8 00 00 00 00       	mov    $0x0,%eax
  6a:	e9 00 00 00 00       	jmpq   6f <main+0x6f>
  6f:	c9                   	leaveq
  70:	c3                   	retq

After the patch

0000000000000000 <main>:
   0:	55                   	push   %rbp
   1:	48 89 e5             	mov    %rsp,%rbp
   4:	48 81 ec 30 00 00 00 	sub    $0x30,%rsp
   b:	48 b8 28 00 00 00 00 	movabs $0x28,%rax
  12:	00 00 00
  15:	49 89 c2             	mov    %rax,%r10
  18:	b8 00 00 00 00       	mov    $0x0,%eax
  1d:	48 89 c6             	mov    %rax,%rsi
  20:	48 8d 45 d8          	lea    -0x28(%rbp),%rax
  24:	48 89 c7             	mov    %rax,%rdi
  27:	4c 89 d2             	mov    %r10,%rdx
  2a:	b8 00 00 00 00       	mov    $0x0,%eax
  2f:	e8 fc ff ff ff       	callq  30 <main+0x30>
  34:	b8 05 00 00 00       	mov    $0x5,%eax
  39:	89 45 ec             	mov    %eax,-0x14(%rbp)
  3c:	b8 00 00 00 00       	mov    $0x0,%eax
  41:	e9 00 00 00 00       	jmpq   46 <main+0x46>
  46:	c9                   	leaveq
  47:	c3                   	retq
 -----------------------------------------------------------------------------------
"c5.c"
int main()
{
  // union st
   struct st
   {
    char c;
    short s;
   // char cc[];
    };
   // union st
  struct st
    ss = { 1, 2, 3};
   // int a = ss;
    char cb[1] = {1,2,3};
    return 0;
}

c5.c:12: warning: excess elements in struct initializer
c5.c:14: warning: excess elements in array initializer
c5.c:14: warning: excess elements in array initializer
2014-05-28 22:09:49 +08:00
jiang
f8b4f59f8b In the local use of local stack, use a global stack in the global time 2014-05-20 14:59:37 +08:00
jiang
e5e7f488e2 int main()
{
	struct st {
		int aa:16;
		int bb:16;
	} s;
	s.aa = 1;
	s.bb = 2;
	return 0;
}
objdump -d:
elf64-x86-64
Disassembly of section .text:

0000000000000000 <main>:
   0:	55                   	push   %rbp
   1:	48 89 e5             	mov    %rsp,%rbp
   4:	48 81 ec 10 00 00 00 	sub    $0x10,%rsp
   b:	b8 01 00 00 00       	mov    $0x1,%eax
  10:	48 89 c1             	mov    %rax,%rcx
  13:	81 e1 ff ff 00 00    	and    $0xffff,%ecx
  19:	8b 55 fc             	mov    -0x4(%rbp),%edx
  1c:	81 e2 00 00 ff ff    	and    $0xffff0000,%edx
  22:	09 d1                	or     %edx,%ecx
  24:	89 4d fc             	mov    %ecx,-0x4(%rbp)
  27:	b8 02 00 00 00       	mov    $0x2,%eax
  2c:	48 89 c1             	mov    %rax,%rcx
  2f:	81 e1 ff ff 00 00    	and    $0xffff,%ecx
  35:	c1 e1 10             	shl    $0x10,%ecx
  38:	8b 55 fc             	mov    -0x4(%rbp),%edx
  3b:	81 e2 ff ff 00 00    	and    $0xffff,%edx
  41:	09 d1                	or     %edx,%ecx
  43:	89 4d fc             	mov    %ecx,-0x4(%rbp)
  46:	b8 00 00 00 00       	mov    $0x0,%eax
  4b:	e9 00 00 00 00       	jmpq   50 <main+0x50>
  50:	c9                   	leaveq
  51:	c3                   	retq

After the patch

Disassembly of section .text:

0000000000000000 <main>:
   0:	55                   	push   %rbp
   1:	48 89 e5             	mov    %rsp,%rbp
   4:	48 81 ec 10 00 00 00 	sub    $0x10,%rsp
   b:	8b 45 fc             	mov    -0x4(%rbp),%eax
   e:	81 e0 00 00 ff ff    	and    $0xffff0000,%eax
  14:	83 c8 01             	or     $0x1,%eax
  17:	89 45 fc             	mov    %eax,-0x4(%rbp)
  1a:	8b 45 fc             	mov    -0x4(%rbp),%eax
  1d:	81 e0 ff ff 00 00    	and    $0xffff,%eax
  23:	81 c8 00 00 02 00    	or     $0x20000,%eax
  29:	89 45 fc             	mov    %eax,-0x4(%rbp)
  2c:	b8 00 00 00 00       	mov    $0x0,%eax
  31:	e9 00 00 00 00       	jmpq   36 <main+0x36>
  36:	c9                   	leaveq
  37:	c3                   	retq
2014-05-17 12:32:00 +08:00
jiang
5d0785d0e1 Add warning 4
num en{a1,a2,a3};
enum en ee;
ee = 0xffffffffff;
    char a;
    a = 0xffff;
2014-05-14 21:01:00 +08:00
jiang
fcb3772a34 Add warning 3
struct st {int a;} ss;
int b;
b = ss;
2014-05-14 20:44:53 +08:00
jiang
07614b5e22 clean '\t' 2014-05-14 12:45:58 +08:00
jiang
c6345b5a8a restore 2dd8587c2f32d17a2cd0443a60a614a3fa9bbe29 2014-05-13 22:05:38 +08:00
jiang
72f466c24c Modify tcc_error ("invalid type",); 2014-05-13 22:00:42 +08:00
jiang
8d5e0cf083 fix 14d0aa450f 2014-05-13 21:57:35 +08:00
jiang
03687729ec Add warning 2
For example:
struct A {
int b: 16;
int c: 16
};
sizeof (struct A);
2014-05-09 22:41:45 +08:00
jiang
14d0aa450f Add warning
For example:
struct A {
int b [];
};
2014-05-09 22:35:19 +08:00
jiang
5e56fb635a Return to: e20c1eb99e
1: The new patch for the other machines still have the problem.
2: libcrt Rename (what if gcc had libcrt as well)
3: parse_number exact problem
4: VT_VLS is to allow tcc
     Compile the following
     int b = 9;
     struct st {
     int a;
     int b [b]
     };
     struct st st1;
     st1.b [8] = 9;
     printf ("% d \ n", st1.b [8]);

     tcc a problem. Due to problems in front, and now can not be improved
5: they commit much, bug difficult to lock, you can not let other people help develop.
6: ('\ t') too

Thanks to Michael and Ray
Their criticism I have benefited!
2014-05-04 13:18:31 +08:00
jiang
089dea355a tcc on i386 are still having problems at work.Thank Roy report again. Struck on several variables can be connected to commit in the register. I am worried whether tcc can run the os. Since my machine is ubuntu 64 bits I can test my machine. 2014-05-03 23:51:09 +08:00
jiang
a0d45c1bcd forget commit tccge.c for i386 2014-05-03 00:39:40 +08:00
jiang
e647c3137d Fix x86-64 vla
For example, it should look like this
High stack
-------------
----- Func_ret_sub
------------
---- Vla stack
-------------
---- Known loc
--------------
Low

Increased loc_stack () function is used for temporary stack management, call save_reg (), released by load ()
Like this
Before use
High
----- Known loc
----
---
----
---- Pop_stack
Low
loc_stack (size, 1)
After use
High
----- Known loc
---- Pop_stack
---
----
----
Low
2014-05-02 23:45:48 +08:00
jiang
6c8207633f Fixes include the double quotes bug
Added push_macro, pop_macro support
Fix pack bug, when output with-E will pack the bug
2014-05-02 11:23:54 +08:00
jiang
5b52a44b52 gen_putz () and struct_copy (), is to reduce the third-party call that
generates faster code tcc
Now only for x86-64
parse_number also to reduce the reliance on third-party libraries, allowing
faster analysis tcc
2014-05-02 09:42:33 +08:00
jiang
59a22d59a2 update for x86_64-gen.c 2014-05-01 20:58:43 +08:00
jiang
2742fbcf95 clean 2014-05-01 15:19:03 +08:00
jiang
87a850f553 fix its own making bug. Improved init_putz (). Modify the tests / Makefile to make the test more secure 2014-05-01 15:15:01 +08:00
jiang
9e3713facd Expansion code again for x86_64-gen 2014-05-01 01:48:50 +08:00
jiang
5af0ea7fb8 Fix va_arg bug, Fix type conversion bug, an increase of loc_stack () function is used to manage loc 2014-04-30 15:26:45 +08:00
jiang
9ff288648b Restore eda2c756ed 2014-04-30 14:24:44 +08:00
jiang
515169f21b Reduce the generation of machine code for x86_64, Less of size 2014-04-29 23:57:22 +08:00
Michael Matz
356c6f6293 Remove unused variable 2014-04-14 05:41:57 +02:00
Michael Matz
fbda78aefe Parse and emit hidden visibility
This adds parsing of (GCC compatible) visibility attribute
in order to mark selected global symbols as hidden.  The generated
.o files contain hidden symbols already, the TCC linker doesn't
yet do the right thing.
2014-04-14 02:53:11 +02:00
Urs Janssen
822f4630e3 add missing prototypes 2014-04-10 11:53:54 +02:00
Thomas Preud'homme
c2422ba87f Fix test for macro nesting 2014-04-07 21:16:04 +08:00
Vincent Lefevre
3e9a7e9d69 Corrected spelling mistakes in comments and strings 2014-04-07 13:31:00 +02:00
grischka
0e43f3aef4 win32: warn people about using undeclared WINAPI functions
*** UNCONDITIONALLY ***

Esp. sihce tinycc winapi headers are not as complete as people might
expect this can otherwise lead to obscure problems that are difficult
to debug.

(Originally 'warn_implicit_function_declaration' was set to 1
always for windows but someone must have deleted that line)
2014-04-06 10:59:40 +02:00
grischka
5879c854fb tccgen: x86_64: fix garbage in the SValue upper bits
This was going wrong (case TOK_LAND in unary: computed labels)
-        vset(&s->type, VT_CONST | VT_SYM, 0);
-        vtop->sym = s;

This does the right thing and is shorter:

+        vpushsym(&s->type, s);


Test case was:

    int main(int argc, char **argv)
    {
        int x;
        static void *label_return = &&lbl_return;
        printf("label_return = %p\n", label_return);
        goto *label_return; //<<<<< here segfault on linux X86_64 without the memset on vset
        printf("unreachable\n");
    lbl_return:
        return 0;
    }


Also::
- Rename "void* CValue.ptr" to more usable "addr_t ptr_offset"
  and start to use it in obvious cases.

- use __attribute__ ((noreturn)) only with gnu compiler

- Revert CValue memsets ("After several days searching ...")
  commit 4bc83ac393

Doesn't mean that the vsetX/vpush thingy isn't brittle and
there still might be bugs as to differences in how the CValue
union  was set and is then interpreted later on.

However the big memset hammer was just too slow (-3% overall).
2014-04-04 20:20:44 +02:00
Thomas Preud'homme
3e56584223 Allow local redefinition of enumerator 2014-03-31 22:59:10 +08:00
Thomas Preud'homme
f272407353 Fix typo in code added by b018bac9c8 2014-03-29 14:57:59 +08:00
Thomas Preud'homme
b125743323 Create bcheck region for argv and arge argument
For program manipulating argv or arge as pointer with construct such as:

(while *argv++) {
  do_something_with_argv;
}

it is necessary to have argv and arge inside a region. This patch create
regions argv and arge) if main is declared with those parameters.
2014-03-29 14:46:26 +08:00
mingodad
4bc83ac393 After several days searching why my code refactoring to remove globals was crashing,
I found the problem it was because CValue stack variables have rubish as it inital values
and assigning to a member that is smaller than the big union item and trying to
recover it later as a different member gives bak garbage.

ST_FUNC void vset(TCCState* tcc_state, CType *type, int r, int v)
{
    CValue cval;
    memset(&cval, 0, sizeof(CValue));

    cval.i = v; //,<<<<<<<<<<< here is the main bug that mix with garbage
    vsetc(tcc_state, type, r, &cval);
}

/* store a value or an expression directly in global data or in local array */
static void init_putv(TCCState* tcc_state, CType *type, Section *sec, unsigned long c,
                      int v, int expr_type)
{
...
        case VT_PTR:
            if (tcc_state->tccgen_vtop->r & VT_SYM) {
                greloc(tcc_state, sec, tcc_state->tccgen_vtop->sym, c, R_DATA_PTR);
            }

//<<< on the next line is where we try to get the assigned value to cvalue.i as cvalue.ull

            *(addr_t *)ptr |= (tcc_state->tccgen_vtop->c.ull & bit_mask) << bit_pos;
            break;

Also this patch makes vla tests pass on linux 32 bits
2014-03-26 20:18:48 +00:00
Thomas Preud'homme
b68499e971 Make parse_btype only accept one basic type
This makes int char c; and struct {} int c; generate an error. Thanks
Mobi Phil for reporting.
2014-03-24 23:40:39 +08:00
Thomas Preud'homme
33cea54dc7 Fix type_to_str test for unsigned int 2014-03-09 13:32:40 +08:00
Thomas Preud'homme
fdb3b10d06 Fix various errors uncovered by static analysis
Reported-by: Carlos Montiers <cmontiers@gmail.com>
2014-03-08 18:38:49 +08:00
Thomas Preud'homme
b0b5165d16 Def signedness != signed != unsigned for char
When checking for exact compatibility between types (such as in
__builtin_types_compatible_p) consider the case of default signedness to
be incompatible with both of the explicit signedness for char. That is,
char is incompatible with signed char *and* unsigned char, no matter
what the default signedness for char is.
2014-02-06 21:40:22 +08:00
Thomas Preud'homme
17314a1fb3 Fix parameter passing of long long bitfield 2014-02-04 20:55:24 +08:00
Thomas Preud'homme
4e5f15c685 switch last 2 params of TOK_memset on ARM
On ARM, TOK_memset is executed via __aeabi_memset which reverse the
order of the last two parameters.
2014-02-03 22:28:08 +08:00
Michael Matz
05c9b76131 Fix floating point unary minus and plus
negate(x) is subtract(-0,x), not subtract(+0,x), which makes
a difference with signed zeros.  Also +x was expressed as x+0,
in order for the integer promotions to happen, but also mangles signed
zeros, so just don't do that with floating types.
2014-01-12 04:44:27 +01:00
Michael Matz
9e11476e15 Fix Fixes for PE x86_64 for fail in code
Applying 64bit relocs assumes that the CVal is initialized to zero
for the whole 64bit.  Consolidate this a bit, at the same time
zeroing the .ull member more consistently when needed.  Fixes segfault
on x86_64-linux using global vars in tcctest.c.
2014-01-11 23:42:58 +01:00
Archidemon
fdf9fba578 Fixes previous fixes 2014-01-10 11:58:16 +06:00
Archidemon
ea7b17f641 Fixes for PE x86_64 for fail in code
int (*fn1)=0x13fde16b5;

and

int fn1(int a) {...}

struct {
  int (*fn2)(int a);
} b = { fn1 };
2014-01-10 09:45:18 +06:00
grischka
3fe2a95d7f be stricter with aliasing
Refactoring (no logical changes):
- use memcpy in tccgen.c:ieee_finite(double d)
- use union to store attribute flags in Sym
Makefile: "CFLAGS+=-fno-strict-aliasing" basically not necessary
anymore but I left it for now because gcc sometimes behaves
unexpectedly without.

Also:
- configure: back to mode 100755
- tcc.h: remove unused variables tdata/tbss_section
- x86_64-gen.c: adjust gfunc_sret for prototype
2014-01-07 14:57:07 +01:00
grischka
2bd0daabbe misc. fixes
- tccgen: error out for cast to void, as in
      void foo(void) { return 1; }
  This avoids an assertion failure in x86_64-gen.c, also.
  also fix tests2/03_struct.c accordingly

- Error: "memory full" - be more specific

- Makefiles: remove circular dependencies, lookup tcctest.c from VPATH

- tcc.h: cleanup lib, include, crt and libgcc search paths"
  avoid duplication or trailing slashes with no CONFIG_MULTIARCHDIR
  (as from 9382d6f1a0)

- tcc.h: remove ";{B}" from PE search path
  in ce5e12c2f9 James Lyon wrote:
  "... I'm not sure this is the right way to fix this problem."
  And the answer is: No, please. (copying libtcc1.a for tests instead)

- win32/build_tcc.bat: do not move away a versioned file
2014-01-06 19:56:26 +01:00
Thomas Preud'homme
8efaa71190 Fix struct ret in variadic fct with ARM hardfloat
The procedure calling standard for ARM architecture mandate the use of
the base standard for variadic function. Therefore, hgen float aggregate
must be returned via stack when greater than 4 bytes and via core
registers else in case of variadic function.

This patch improve gfunc_sret() to take into account whether the
function is variadic or not and make use of gfunc_sret() return value to
determine whether to pass a structure via stack in gfunc_prolog(). It
also take advantage of knowing if a function is variadic or not move
float result value from VFP register to core register in gfunc_epilog().
2014-01-06 22:57:05 +08:00
Thomas Preud'homme
eda2c756ed 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.
2014-01-04 21:10:05 +08:00
Thomas Preud'homme
3eed3506b4 Fix negation of 0.0 and -0.0 2014-01-04 17:07:58 +08:00