aboutsummaryrefslogtreecommitdiff
path: root/tccgen.c
Commit message (Collapse)AuthorAgeFilesLines
* Make tcc work after self-compiling with bounds-check enabledKirill Smelkov2012-12-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For vstack Fabrice used the trick to initialize vtop to &vstack[-1], so that on first push, vtop becomes &vstack[0] and a value is also stored there - everything works. Except that when tcc is compiled with bounds-checking enabled, vstack - 1 returns INVALID_POINTER and oops... Let's workaround it with artificial 1 vstack slot which will not be used, but only serve as an indicator that pointing to &vstack[-1] is ok. Now, tcc, after being self-compiled with -b works: $ ./tcc -B. -o tccb -DONE_SOURCE -DCONFIG_MULTIARCHDIR=\"i386-linux-gnu\" tcc.c -ldl $ cd tests $ ../tcc -B.. -run tcctest.c >1 $ ../tccb -B.. -run tcctest.c >2 $ diff -u 1 2 and note, tcc's compilation speed is not affected: $ ./tcc -B. -bench -DONE_SOURCE -DCONFIG_MULTIARCHDIR=\"i386-linux-gnu\" -c tcc.c before: 8270 idents, 47221 lines, 1527730 bytes, 0.152 s, 309800 lines/s, 10.0 MB/s after: 8271 idents, 47221 lines, 1527733 bytes, 0.152 s, 310107 lines/s, 10.0 MB/s But note, that `tcc -b -run tcc` is still broken - for example it crashes on $ cat x.c double get100 () { return 100.0; } $ ./tcc -B. -b -DTCC_TARGET_I386 -DCONFIG_MULTIARCHDIR=\"i386-linux-gnu\" -run \ -DONE_SOURCE ./tcc.c -B. -c x.c Runtime error: dereferencing invalid pointer ./tccpp.c:1953: at 0xa7beebdf parse_number() (included from ./libtcc.c, ./tcc.c) ./tccpp.c:3003: by 0xa7bf0708 next() (included from ./libtcc.c, ./tcc.c) ./tccgen.c:4465: by 0xa7bfe348 block() (included from ./libtcc.c, ./tcc.c) ./tccgen.c:4440: by 0xa7bfe212 block() (included from ./libtcc.c, ./tcc.c) ./tccgen.c:5529: by 0xa7c01929 gen_function() (included from ./libtcc.c, ./tcc.c) ./tccgen.c:5767: by 0xa7c02602 decl0() (included from ./libtcc.c, ./tcc.c) that's because lib/bcheck.c runtime needs more fixes -- see next patches.
* Add support for __builtin_frame_address(level)Kirill Smelkov2012-11-161-6/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Continuing d6072d37 (Add __builtin_frame_address(0)) implement __builtin_frame_address for levels greater than zero, in order for tinycc to be able to compile its own lib/bcheck.c after cffb7af9 (lib/bcheck: Prevent __bound_local_new / __bound_local_delete from being miscompiled). I'm new to the internals, and used the most simple way to do it. Generated code is not very good for levels >= 2, compare gcc tcc level=0 mov %ebp,%eax lea 0x0(%ebp),%eax level=1 mov 0x0(%ebp),%eax mov 0x0(%ebp),%eax level=2 mov 0x0(%ebp),%eax mov 0x0(%ebp),%eax mov (%eax),%eax mov %eax,-0x10(%ebp) mov -0x10(%ebp),%eax mov (%eax),%eax level=3 mov 0x0(%ebp),%eax mov 0x0(%ebp),%eax mov (%eax),%eax mov (%eax),%ecx mov (%eax),%eax mov (%ecx),%eax But this is still an improvement and for bcheck we need level=1 for which the code is good. For the tests I had to force gcc use -O0 to not inline the functions. And -fno-omit-frame-pointer just in case. If someone knows how to improve the generated code - help is appreciated. Thanks, Kirill Cc: Michael Matz <matz@suse.de> Cc: Shinichiro Hamaji <shinichiro.hamaji@gmail.com>
* forbid invalid comparison of structHitoshi Mitake2012-11-051-0/+2
| | | | | Current tcc permits comparison of structs and comparison between struct and other typed values.
* Fix commit 85f6fad3a6acbfa07a3dc45b673965fc26890d8eThomas Preud'homme2012-10-251-1/+2
| | | | | Don't reset nocode_wanted with saved_nocode_wanted if it hasn't been modified (and hence saved_nocode_wanted is uninitialized).
* Error out in case of variable name clashThomas Preud'homme2012-10-251-3/+21
| | | | | Error out when two local variable with same name are defined in the same scope. This fixes bug #15597 in savannah's BTS.
* Forbid VLA as static variablesThomas Preud'homme2012-10-251-1/+6
| | | | | | | | | | | Currently, VLA are not forbidden for static variable. This leads to problems even if for fixed-size array when the size expression uses the ternary operator (cond ? then-value : else-value) because it is parsed as a general expression which leads to code generated in this case. This commit solve the problem by forbidding VLA for static variables. Although not required for the fix, avoiding code generation when the expression is constant would be a nice addition though.
* get_reg(): try to free r2 for an SValue firstThomas Preud'homme2012-07-111-4/+5
| | | | | | | | | | To be able to load a long long value correctly on i386, gv() rely on the fact that when get_reg() look at an SValue it tries first to free the register in r2 and then r. More information about the context can be found at http://lists.nongnu.org/archive/html/tinycc-devel/2012-06/msg00017.html and later at http://lists.nongnu.org/archive/html/tinycc-devel/2012-07/msg00021.html
* Incorrect shift result type on unsigned short first argument.Vincent Lefevre2012-07-061-1/+3
| | | | | | The code for shifts is now similar to code for binary arithmetic operations, except that only the first argument is considered, as required by the ISO C standard.
* Incorrect shift result type with 64-bit ABIVincent Lefevre2012-06-271-0/+3
| | | | | | | | | | | | | | | On 2012-06-26 15:07:57 +0200, Vincent Lefevre wrote: > ISO C99 TC3 says: [6.5.7#3] "The integer promotions are performed on > each of the operands. The type of the result is that of the promoted > left operand." I've written a patch (attached). Now the shift problems no longer occur with the testcase and with GNU MPFR's "make check". -- Vincent Lefèvre <vincent@vinc17.net> - Web: <http://www.vinc17.net/> 100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/> Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
* Add support for arm hardfloat calling conventionThomas Preud'homme2012-06-051-6/+14
| | | | | See Procedure Call Standard for the ARM Architecture (AAPCS) for more details.
* Fix removal of vnrottThomas Preud'homme2012-06-051-1/+1
| | | | Make vrotb ST_FUNC so that arm-gen.c can use vrotb.
* Fix comparing comparisonsMichael Matz2012-04-181-0/+8
| | | | | | | | | | | Sometimes the result of a comparison is not directly used in a jump, but in arithmetic or further comparisons. If those further things do a vswap() with the VT_CMP as current top, and then generate instructions for the new top, this most probably destroys the flags (e.g. if it's a bitfield load like in the example). vswap() must do the same like vsetc() and not allow VT_CMP vtops to be moved down.
* Make sizeof() be of type size_tMichael Matz2012-04-181-3/+14
| | | | | | | | This matters when sizeof is directly used in arithmetic, ala "uintptr_t t; t &= -sizeof(long)" (for alignment). When sizeof isn't size_t (as it's specified to be) this masking will truncate the high bits of the uintptr_t object (if uintptr_t is larger than uint).
* Fix detection of labels with a typedef nameMichael Matz2012-04-181-1/+20
| | | | | | | | | | | | | | This needs to be accepted: typedef int foo; void f (void) { foo: return; } namespaces for labels and types are different. The problem is that the block parser always tries to find a decl first and that routine doesn't peek enough to detect this case. Needs some adjustments to unget_tok() so that we can call it even when we already called it once, but next() didn't come around restoring the buffer yet. (It lazily does so not when the buffer becomes empty, but rather when the next call detects that the buffer is empty, i.e. it requires two next() calls until the unget buffer gets switched back).
* Fix bitfield loads into char/short.Michael Matz2012-04-181-2/+3
| | | | | | Removes a premature optimization of char/short loads rewriting the source type. It did so also for bitfield loads, thereby removing all the shifts/maskings.
* Fix conversion in a?0:ptr.Michael Matz2012-04-181-5/+14
| | | | | | (cond ? 0 : ptr)->member wasn't handled correctly. If one arm is a null pointer constant (which also can be a pointer) the result type is that of the other arm.
* Remove vnrott (duplicate vrotb)Thomas Preud'homme2012-03-141-16/+0
|
* Error out when assigning void value.Thomas Preud'homme2012-01-221-0/+2
| | | | | | | | tcc should now error out when compiling code like: VOID ExitProcess(UINT uExitCode); (…) retCode = ExitProcess(pi.dwProcessId);
* rename error/warning -> tcc_(error/warning)grischka2011-08-111-75/+75
|
* x86-64: fix flags and zero-pad long doublesgrischka2011-08-061-1/+5
| | | | | | | | | | This fixes a bug introduced in commit 8d107d9ffd8126d82b1c56be47431a6bcef39f08 that produced wrong code because of interference between 0x10 bits VT_CONST and x86_64-gen.c:TREG_MEM Also fully zero-pad long doubles on x86-64 to avoid random bytes in output files which disturb file comparison.
* Accept colon separated paths with -L and -Igrischka2011-08-011-0/+9
| | | | | | | | | | | | | | | | | | This allows passing colon separated paths to tcc_add_library_path tcc_add_sysinclude_path tcc_add_include_path Also there are new configure variables CONFIG_TCC_LIBPATH CONFIG_TCC_SYSINCLUDE_PATHS which define the lib/sysinclude paths all in one and can be overridden from configure/make For TCC_TARGET_PE semicolons (;) are used as separators Also, \b in the path string is replaced by s->tcc_lib_path (CONFIG_TCCDIR rsp. -B option)
* Revert "Force const. expr. in expr_cond outside function"Thomas Preud'homme2011-07-311-1/+1
| | | | | This reverts commit b2f5ee9b2de40e26ba3d92cf3950be6da7766b7d as it's useless on mob.
* Force const. expr. in expr_cond outside functionThomas Preud'homme2011-07-311-1/+1
| | | | | | Since no code should be generated outside a function, force expr_cond to only consider constant expression when outside a function since the generic code can generate some code.
* re-added negative-array-size testcase and fixed fix for itJoe Soroka2011-07-221-3/+3
|
* Revert "better constant handling for expr_cond"grischka2011-07-161-4/+1
| | | | | It produced wrong code with one of my test projects. This reverts commit cd3d1a45f34be3c9a358f1743bcaf8aac897992e.
* win64: va_arg with structuresgrischka2011-07-141-0/+4
|
* tccgen: reset aligned attribute for next typegrischka2011-07-141-0/+1
| | | | | | | | | | | | Basically, with: typedef __attribute__((aligned(16))) struct _xyz { ... } xyz, *pxyz; we want the struct aligned but not the pointer. FIXME: This patch is a hack, waiting for someone in the knowledge of correct __attribute__ semantics.
* handle arrays with a flexible member but no initializerJoe Soroka2011-07-111-1/+1
|
* better constant handling for expr_condJoe Soroka2011-07-111-1/+4
|
* Remove unused variablesThomas Preud'homme2011-05-161-1/+6
| | | | | Remove unused local variables and declare them conditionally when they are used only on some architectures.
* use of TOK_alloca breaks cross compiler buildJoe Soroka2011-04-121-0/+4
| | | | | | | | | | | VLA inserts a call to alloca via enum TOK_alloca, but TOK_alloca only exists on I386 and X86_64 targets. This patch just emits an error at compile-time if someone tries to compile some VLA code for a TOK_alloca-less target. The best solution might be to just push the problem to link-time, since the existence-or-not of a alloca implementation can only be determined by linking. It seems like just declaring TOK_alloca unconditionally would achieve that, but for now, this at least gets the cross compilers to build.
* simplify/rollback VLA pointer subtractionJoe Soroka2011-04-111-10/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I don't know if it makes a difference to gen_op(TOK_PDIV) or not, but logically the ptr1_is_vla test in TP's VLA patch seems out of order, where the patch to fix it would be: ------------------------------------------------------------------ @@ -1581,15 +1581,15 @@ ST_FUNC void gen_op(int op) u = pointed_size(&vtop[-1].type); } gen_opic(op); + if (ptr1_is_vla) + vswap(); /* set to integer type */ #ifdef TCC_TARGET_X86_64 vtop->type.t = VT_LLONG; #else vtop->type.t = VT_INT; #endif - if (ptr1_is_vla) - vswap(); - else + if (!ptr1_is_vla) vpushi(u); gen_op(TOK_PDIV); } else { ------------------------------------------------------------------ Instead of that patch, which increases the complexity of the code, this one fixes the problem by just rolling back and retrying with a simpler approach.
* remove no-longer-necessary naive fix for vla vstack leakJoe Soroka2011-04-091-5/+0
|
* prevent internal segfault on apparent VLA at file scopeJoe Soroka2011-04-091-0/+2
|
* VLA fix [3/3]: store VLA sizeofs in anonymous runtime stack varsJoe Soroka2011-04-091-33/+22
|
* VLA fix [2/3]: removed VT_ARRAY from VT_VLA typesJoe Soroka2011-04-081-20/+11
| | | | | | | | | A VLA is not really an array, it's a pointer-to-an-array. Making this explicit allows us to back out a few parts of the original VLA patch and paves the way for the next part of the fix, where a VLA will be stored on the runtime stack as a pointer-to-an-array, rather than on the compile- time stack as a Sym*.
* move a comment to its correct locationJoe Soroka2011-04-081-1/+1
|
* add naive workaround for VLA vstack leakJoe Soroka2011-04-081-0/+5
|
* VLA bcheck works via bound alloca; add test, remove warningJoe Soroka2011-04-061-3/+1
|
* clarify post_type() VT_STORAGE handling by moving it outJoe Soroka2011-04-061-7/+7
|
* re-apply VLA by Thomas Preud'hommeJoe Soroka2011-04-061-30/+130
|
* handle c99 flexible array members less hackilyJoe Soroka2011-03-181-1/+18
|
* revert complicated & broken flexible array member handlingJoe Soroka2011-03-181-18/+4
|
* fix c99 for-loop init decl scope (thanks: grischka)Joe Soroka2011-03-081-0/+2
| | | | see http://lists.nongnu.org/archive/html/tinycc-devel/2011-03/msg00005.html
* clarify support for functions returning an array (try#2)Joe Soroka2011-03-081-4/+9
| | | | | fixes first attempt: http://repo.or.cz/w/tinycc.git/commitdiff/31fe1cc
* revert last commit. fails "make test"Joe Soroka2011-03-081-8/+5
| | | | | | | | | test target in Makefile does not depend on tcc. i'm not sure why, but i can think of at least one good reason. in my local tree I have it modified to do so, but somehow inadvertently reverted that so when i did "make test" before committing, it didn't actually test my changes. sorry.
* clarify support for functions returning an arrayJoe Soroka2011-03-081-5/+8
| | | | | | | | | previously, tcc would accept a prototype of a function returning an array, but not giving those functions bodies nor calling them. it seems that gcc has never supported them, so we should probably just error out... but it's possible that someone already using tcc includes some header that contains an unused prototype for one, so let's continue to support that.
* support c99 for-loop init decls (2nd attempt)Joe Soroka2011-03-081-3/+18
|
* partially revert e23194aJoe Soroka2011-03-081-19/+3
| | | | see http://lists.nongnu.org/archive/html/tinycc-devel/2011-03/msg00002.html
* revert last 3 commits. will find better way.Joe Soroka2011-03-081-96/+85
|