aboutsummaryrefslogtreecommitdiff
path: root/tccgen.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix sizeof(char[a])Michael Matz2016-12-151-12/+15
| | | | | The sizes of VLAs need to be evaluated even inside sizeof, i.e. when nocode_wanted is set.
* Fix __builtin_constant_p(1000/x)Michael Matz2016-12-151-0/+17
| | | | | was incorrectly treated as constant because the vpop removed all traces of non-constness.
* Fix enum bitfields passed to stdarg functionsMichael Matz2016-12-151-0/+1
| | | | | VT_ENUM types use the .ref member and can be VT_BITFIELD, so we need to copy it as well. Simply do it always.
* Addresses of non-weak symbols are non-zeroMichael Matz2016-12-151-1/+3
| | | | Use this fact in some foldings of comparisons. See testcase.
* Fix access-after-free with statement expressionsMichael Matz2016-12-151-26/+27
| | | | | | | | | | | | The return value of statement expressions might refer to local symbols, so those can't be popped. The old error message always was just a band-aid, and since disabling it for pointer types it wasn't effective anyway. It also never considered that also the vtop->sym member might have referred to such symbols (see the testcase with the local static, that used to segfault). For fixing this (can be seen better with valgrind and SYM_DEBUG) simply leave local symbols of stmt exprs on the stack.
* enums and ints are compatibleMichael Matz2016-12-151-11/+31
| | | | | | | But like GCC do warn about changes in signedness. The latter leads to some changes in gen_assign_cast to not also warn about unsigned* = int* (where GCC warns, but only with extra warnings).
* enums and ints are compatibleMichael Matz2016-12-151-0/+8
|
* struct-init: Support range inits for local varsMichael Matz2016-12-151-17/+28
| | | | Implement missing support for range init for local variables.
* struct-init: Allow member initialization from qualified lvaluesMichael Matz2016-12-151-1/+4
| | | | See testcase.
* struct-init: Correctly parse unnamed member initializersMichael Matz2016-12-151-21/+51
| | | | | | | | | | | | | For union U { struct {int a,b}; int c; }; union U u = {{ 1, 2, }}; The unnamed first member of union U needs to actually exist in the structure so initializer parsing isn't confused about the double braces. That means also the a and b members must be part of _that_, not of union U directly. Which in turn means we need to do a bit more work for field lookup. See the testcase extension for more things that need to work.
* struct-init: Cleanup some moreMichael Matz2016-12-151-98/+103
| | | | | Some parameters aren't actually necessary. Also join the two parsing loops for the initializer list of arrays and structs.
* struct-init: CleanupMichael Matz2016-12-151-102/+12
| | | | | | | Remove dead code and variables. Properly check for unions when skipping fields in initializers. Make tests2/*.expect depend on the .c files so they are automatically rebuilt when the latter change.
* struct-init: Implement initializing subaggregatesMichael Matz2016-12-151-39/+59
| | | | | | E.g. "struct { struct S s; int a;} = { others, 42 };" if 'others' is also a 'struct S'. Also when the value is a compound literal. See added testcases.
* struct-init: ReimplementMichael Matz2016-12-151-78/+106
| | | | | | Start reimplementing the whole initializer handling to be conforming to ISO C. This patch just reimplements current functionality to prepare for further changes, all tests pass.
* Support attribute between double pointer starsMichael Matz2016-12-151-4/+5
| | | | "int * __attribute__((something)) *" is supported by GCC.
* Fix function to pointer conversionMichael Matz2016-12-151-0/+13
| | | | | | | | This snippet is valid: void foo(void); ... foo + 42 ... the function designator is converted to pointer to function implicitely. gen_op didn't do that and bailed out.
* Fix parsing array typedefs of unknown sizeMichael Matz2016-12-151-0/+8
| | | | | | | | | | | This must compile: typedef int arrtype1[]; arrtype1 sinit19 = {1}; arrtype1 sinit20 = {2,3}; and generate two arrays of one resp. two elements. Before the fix the determined size of the first array was encoded in the type directly, so sinit20 couldn't be parsed anymore (because arrtype1 was thought to be only one element long).
* Implement __builtin_choose_exprMichael Matz2016-12-151-0/+29
| | | | Follows GCC implementation.
* Fix parsing attributes for struct declsMichael Matz2016-12-151-4/+2
| | | | | | | | | | | Given this code: struct __attribute__((...)) Name {...}; TCC was eating "Name", hence generating an anonymous struct. It also didn't apply any packed attributes to the parsed members. Both fixed. The testcase also contains a case that isn't yet handled by TCC (under a BROKEN #define).
* inline asm: accept concatenated strings in constraintsMichael Matz2016-12-151-1/+1
| | | | | This really should be handled implicitly in the preprocessor, but for now this is enough.
* Accept symbols in initializers also on 64 bitMichael Matz2016-12-151-3/+13
| | | | Those should use long or long long type, and generate a 64bit reloc.
* Accept empty struct member declsMichael Matz2016-12-151-1/+4
| | | | | | | struct S { /*nothing*/; int a; }; is an acceptable struct declaration, there may be stray semicolons in the member list.
* Accept concatenated strings in attributesMichael Matz2016-12-151-25/+29
| | | | | attribute(section("one" "two")) should be accepted (the section name being "onetwo"), it's normal string concatenation.
* arm64: Fix regression introduced by 6245db9.Edmund Grimley Evans2016-12-051-0/+4
|
* Rename add_elf_sym to set_elf_symThomas Preud'homme2016-12-031-1/+1
| | | | | | | | | | add_elf_sym is a confusing name because it is not clear what the function does compared to put_elf_sym. As a matter of fact, put_elf_sym also adds a symbol in a symbol table. Besides, "add_elf_sym" fails to convey that the function can be used to update a symbol (for instance its value). "set_elf_sym" seems like a more appropriate name: it will set a symbol to a given set of properties (value, size, etc.) and create a new one if non exist for that name as one would expect.
* Implement gcc bitfield algorithm; add -mms-bitfieldsDavid Mertens2016-11-281-7/+23
|
* tccgen: fix inline_functions double free fixgrischka2016-11-111-4/+2
|
* tccgen: inline_functions double free fixgrischka2016-11-111-7/+9
| | | | | | Fix double free of the inline function token_string which could happen when an error/longjmp occurred while compiling the inline function.
* bcheck: access fields of local structs w/o bcheckPavlas, Zdenek2016-11-101-3/+3
| | | | Revert previous commit, this is probably a better fix.
* bcheck: add structs to local regionsPavlas, Zdenek2016-11-091-2/+2
| | | | | | | | int test() { struct { int i; } s = { 42 }; return s.i; // bound checked }
* tccpp_new/delete and other cleanupsgrischka2016-10-171-20/+13
|
* x86-64: Fix long long bugMichael Matz2016-10-171-2/+7
| | | | | | | With the last improvements to lexpand it's now harmful to use on native 64bit platforms when not necessary. For gv_dup it's not necessary there. It can still be used with really transforming a 64bit value into two 32bit ones.
* i386: do not 'lexpand' into registers necessarilygrischka2016-10-161-10/+16
| | | | | | | | | | | | | | Previously, long longs were 'lexpand'ed into two registers always. Now, it expands - constants into two constants (lo-part, hi-part) - variables into two lvalues with offset+4 for the hi-part. This makes long long operations look a bit nicer. Also: don't apply i386 'inc/dec' optimization if carry generation is wanted.
* tccgen/32bits: fix unsigned long long -> int castgrischka2016-10-161-3/+3
| | | | | | | | | | | | | | | | | | | gen_cast() failed to truncate long long's if they were unsigned, which was causing mess on the vstack. There was a similar bug here tccgen: 32bits: fix PTR +/- long long ed15cddacd145c74e4600af50f6616ba59ca0d8d Both were not visible until this patch tccgen: arm/i386: save_reg_upstack b691585785086024549cfb9ac65f3397263965aa I'd still assume that this patch is correct per se. Also: - remove 2x !nocode_wanted (we are already under a general "else if (!nocode_wanted)" clause above).
* #define __GNUC__ = 2.1grischka2016-10-151-0/+4
| | | | | | | | | | __GNUC__ nowadays as macro seems to mean the "GNU C dialect" rather than the compiler itself. See also http://gcc.gnu.org/ml/gcc/2008-07/msg00026.html This patch will probably cause problems of various kinds but maybe we should try nonetheless.
* tccgen/tccelf: move code from libtcc.cgrischka2016-10-151-14/+214
|
* Fix misleading indentationMichael Matz2016-10-141-3/+3
|
* tccgen: 32bits: fix PTR +/- long longgrischka2016-10-131-0/+22
| | | | | | | | | | | | | | | | | | | | | | | Previously in order to perform a ll+ll operation tcc was trying to 'lexpand' PTR in gen_opl which did not work well. The case: int printf(const char *, ...); char t[] = "012345678"; int main(void) { char *data = t; unsigned long long r = 4; unsigned a = 5; unsigned long long b = 12; *(unsigned*)(data + r) += a - b; printf("data %s\n", data); return 0; }
* gcase() clean upPavlas, Zdenek2016-10-111-33/+32
| | | | remove tail recursion, simplify
* Fix handling of case_reg in switch statement.Edmund Grimley Evans2016-10-101-3/+18
| | | | | | | | | | 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. This bug fix was first applied as ff3f9aa (20 Feb 2015), but the fix was reverted by fc0fc6a (21 Sep 2016, "switch: collect case ranges first, then generate code"). Here the fix is updated for the new code.
* tccpp : "tcc -E -P" : suppress empty linesgrischka2016-10-091-1/+1
| | | | | | | | | Also: - regenerate all tests/pp/*.expect with gcc - test "insert one space" feature - test "0x1E-1" in asm mode case - PARSE_FLAG_SPACES: ignore \f\v\r better - tcc.h: move some things
* tccgen.c: make vla_runtime_type_size always return the alignmentDaniel Glöckner2016-10-091-0/+1
|
* tccgen.c: fix multi-register structure return when not on stackDaniel Glöckner2016-10-081-9/+14
| | | | | | | | | | We need to preserve the type of the pointer to the structure, f.ex. when a global structure is returned. This is not a perfect solution. Registers loaded in the first iteration might be overwritten in a following iteration as the register is no longer on vtop. This is not a problem for ARM32 as gfunc_sret returns a maximum of 1 in the integer case.
* tccgen.c: use correct type for storing long double constantsDaniel Glöckner2016-10-081-1/+6
|
* Misc. fixesgrischka2016-10-051-1/+2
| | | | | | | | | | | | | | | | | | | | Makefile : - do not 'uninstall' peoples /usr/local/doc entirely libtcc.c : - MEM_DEBUG : IDE-friendly output "file:line: ..." - always ELF for objects tccgen.c : - fix memory leak in new switch code - move static 'in_sizeof' out of function profiling : - define 'static' to empty resolve_sym() : - replace by dlsym() win32/64: fix R_XXX_RELATIVE fixme - was fixed for i386 already in 8e4d64be2fc1d707c7800c5096f6e0ea22cbd - do not -Lsystemdir if compiling to .o
* tccgen: arm/i386: save_reg_upstackgrischka2016-10-041-18/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | tccgen.c:gv() when loading long long from lvalue, before was saving all registers which caused problems in the arm function call register parameter preparation, as with void foo(long long y, int x); int main(void) { unsigned int *xx[1], x; unsigned long long *yy[1], y; foo(**yy, **xx); return 0; } Now only the modified register is saved if necessary, as in this case where it is used to store the result of the post-inc: long long *p, v, **pp; v = 1; p = &v; p[0]++; printf("another long long spill test : %lld\n", *p); i386-gen.c : - found a similar problem with TOK_UMULL caused by the vstack juggle in tccgen:gen_opl() (bug seen only when using EBX as 4th register)
* Alternative fix for "Incorrect function call code on ARMv6"grischka2016-10-031-0/+5
| | | | | | | | | | | "make test" crashes without that "save_regs()". This partially reverts commit 49d3118621a68f6583228f123efd16f0f803d908. Found another solution: In a 2nd pass Just look if any of the argument registers has been saved again, and restore if so.
* switch: binary searchPavlas, Zdenek2016-10-031-23/+51
|
* switch: fix label sortingPavlas, Zdenek2016-10-031-2/+6
|
* tccgen: fix long long -> char/short castgrischka2016-10-021-1/+4
| | | | | | | | | | | | | | | | | | | | | | | This was causing assembler bugs in a tcc compiled by itself at i386-asm.c:352 when ExprValue.v was changed to uint64_t: if (op->e.v == (int8_t)op->e.v) op->type |= OP_IM8S; A general test case: #include <stdio.h> int main(int argc, char **argv) { long long ll = 4000; int i = (char)ll; printf("%d\n", i); return 0; } Output was "4000", now "-96". Also: add "asmtest2" as asmtest with tcc compiled by itself