aboutsummaryrefslogtreecommitdiff
path: root/tccgen.c
Commit message (Collapse)AuthorAgeFilesLines
* arm64: Fix a case of dead code suppressionMichael Matz2016-12-151-4/+6
| | | | 82_nocode_wanted.c:kb_wait_2_1 was miscompiled on arm64.
* struct-layout: Allow lowering of member alignmentMichael Matz2016-12-151-2/+1
| | | | | | when an alignment is explicitely given on the member itself, or on its types attributes then respect it always. Was only allowed to increase before, but GCC is allowing it.
* Support large alignment requestsMichael Matz2016-12-151-6/+30
| | | | | | | | The linux kernel has some structures that are page aligned, i.e. 4096. Instead of enlarging the bit fields to specify this, use the fact that alignment is always power of two, and store only the log2 minus 1 of it. The 5 bits are enough to specify an alignment of 1 << 30.
* struct-layout: cleanup code a bitMichael Matz2016-12-151-94/+56
|
* bitfields: Fix MS layout some moreMichael Matz2016-12-151-4/+9
| | | | | | | | | | | | | | | | Another corner case: struct foo6_1 { char x; short p:8; short :0; short :0; short p2:8; char y; }; In MS layout the second anon :0 bit-field does _not_ adjust size or alignment of the struct again. The first one does, though.
* bitfields: fix PCC layoutMichael Matz2016-12-151-23/+28
| | | | | Fixes some corner cases in PCC layout. Testcases coming up.
* bitfields: Implement MS compatible layoutMichael Matz2016-12-151-7/+30
| | | | | | | | Bit-fields are layed out differently in visual C, this implements a compatible mode. Checked against Visual C/C++ 2016. Unfortunately the GCC implementation of MS layout (behind -mms-bitfields) actually is different, and hence not compatible with MS in all cases :-/
* Fix struct layout some moreMichael Matz2016-12-151-40/+113
| | | | | | Anonymous sub-sub-members weren't handled correctly. Bit-fields neither: this implements PCC layout for now. It temporarily disables MS-compatible bit-field layout.
* Split off record layoutingMichael Matz2016-12-151-78/+114
| | | | | | | | | | | Such struct decl: struct S { char a; int i;} __attribute__((packed)); should be accepted and cause S to be five bytes long (i.e. the packed attribute should matter). So we can't layout the members during parsing already. Split off the offset and alignment calculation for this.
* Fix 64bit enums and switch casesMichael Matz2016-12-151-38/+76
| | | | | | | See testcases. We now support 64bit case constants. At the same time also 64bit enum constants on L64 platforms (otherwise the Sym struct isn't large enough for now). The testcase also checks for various cases where sign/zero extension was confused.
* Fix miscompile with dead switchesMichael Matz2016-12-151-7/+9
| | | | | | | | In certain very specific situations (involving switches with asms inside dead statement expressions) we could generate invalid code (clobbering the buffer so much that we generated invalid instructions). Don't emit the decision table if the switch itself is dead.
* 64bit: Fix addends > 32 bitsMichael Matz2016-12-151-1/+6
| | | | | | If a symbolic reference is offsetted by a constant > 32bit the backends can't deal with that, so don't construct such values.
* Fix initializing members multiple timesMichael Matz2016-12-151-0/+11
| | | | | | | When intializing members where the initializer needs relocations and the member is initialized multiple times we can't allow that to lead to multiple relocations to the same place. The last one must win.
* Support local register variablesMichael Matz2016-12-151-3/+17
| | | | | | | | | Similar to GCC a local asm register variable enforces the use of a specified register in asm operands (and doesn't otherwise matter). Works only if the variable is directly mentioned as operand. For that we now generally store a backpointer from an SValue to a Sym when the SValue was the result of unary() parsing a symbol identifier.
* Fix const folding of 64bit pointer constantsMichael Matz2016-12-151-2/+2
| | | | See testcase.
* struct-init: Copy relocs for compound literalsMichael Matz2016-12-151-0/+26
| | | | | When copying the content of compound literals we must include relocations as well.
* opt: Don't emit inline functions from dead codeMichael Matz2016-12-151-1/+1
| | | | | Inside dead code don't regard inline functions as being referenced.
* opt: constprop also 'cond && 0'Michael Matz2016-12-151-62/+74
| | | | | | We didn't handle constants in logical expressions when they weren't the first operand. Some reordering in the loop structure is enough to handle them.
* opt: Make break and goto not fallthroughMichael Matz2016-12-151-2/+17
| | | | | As we can optimize dead code a bit already it's fitting to disable code emission after break and goto.
* opt: Start optimizing dead code a bitMichael Matz2016-12-151-2/+15
| | | | | | | If a condition is always zero/non-zero we can omit the then or else code. This is complicated a bit by having to deal with labels that might make such code reachable without us yet knowing during parsing.
* Revert "Reject jumping inside stmtexprs"Michael Matz2016-12-151-7/+1
| | | | | | | | | | | | | Not fully thought out. You can't jump inside stmt exprs, but you can jump out of them. So there's a difference between undefined but declared labels at the end of stmt exprs and those defined inside. Additionally it should also be checked if a label defined inside a stmt expr was tentatively created as declared from outside. I'm not prepared doing that right now, so simply revert. This reverts commit 9160e4cab9147d77840cc44a285031fdb4640cf9.
* Factor out const condition detectionMichael Matz2016-12-151-10/+22
| | | | Creating condition_3way for this.
* Reject jumping inside stmtexprsMichael Matz2016-12-151-1/+7
| | | | | | | | | | | | One can't jump into statement expressions from outside them, like the following: int i = ({ label: foo(); 42; }); goto label; We reject this by making the labels simply not available outside (GCC has a nicer error message about jumping into a statement expression).
* Fix more nocode_wanted jump problemsMichael Matz2016-12-151-4/+10
| | | | | | | In statement expression we really mustn't emit backward jumps under nocode_wanted (they will form infinte loops as no expressions are evaluated). Do-while and explicit loop with gotos weren't handled.
* Fix aliases on 64 bitMichael Matz2016-12-151-2/+2
| | | | Use correct width ELF structure.
* 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.