aboutsummaryrefslogtreecommitdiff
path: root/tccgen.c
Commit message (Collapse)AuthorAgeFilesLines
* Extend type_to_strMichael Matz2017-05-021-1/+11
| | | | to also print storage-class specifiers.
* Reorganize type parsingMichael Matz2017-05-021-64/+57
| | | | | Various corner cases for declarator parsing were incorrect. This reorganizes and fixes it, and somewhat simplifies it as well.
* Tidy typename parsing a bitMichael Matz2017-05-021-26/+16
|
* Tidy arg parsing for builtinsMichael Matz2017-05-021-76/+52
| | | | Saves some lines of code.
* Remove VT_REFMichael Matz2017-05-021-10/+2
| | | | | | The canonical way to describe a local variable that actually holds the address of an lvalue is VT_LLOCAL. Remove the last user of VT_REF, and handling of it, thereby freeing a flag for SValue.r.
* Fix bogus check for VT_LLOCAL typesMichael Matz2017-05-021-4/+8
| | | | | | VT_LLOCAL is a flag on .r, not on type.t. Fixing this requires minor surgery for compound literals which accidentally happened to be subsumed by the bogus test.
* fix __builtin_expectMichael Matz2017-05-021-25/+2
| | | | | | | | the second argument can be an arbitrary expression (including side-effects), not just a constant. This removes the last user of expr_lor_const and hence also that function (and expr_land_const). Also the argument to __builtin_constant_p can be only a non-comma expression (like all functions arguments).
* Fix more bitfield corner casesMichael Matz2017-05-011-0/+3
| | | | | | | Our code generation assumes that it can load/store with the bit-fields base type, so bit_pos/bit_size must be in range for this. We could change the fields type or adjust offset/bit_pos; we do the latter.
* Fix last changeMichael Matz2017-05-011-1/+1
| | | | | Skipping anonymous bit-fields is correct, but not other anonymous ones like unions or structs.
* Remove a bit-field TODOMichael Matz2017-04-291-0/+2
| | | | | | Checked the lcc testsuite for bitfield stuff (in cq.c and fields.c), fixed one more error in initializing unnamed members (which have to be skipped), removed the TODO.
* Fix char bitfields corner caseMichael Matz2017-04-291-1/+1
| | | | See testcase.
* final adjustments for releasegrischka2017-04-251-9/+0
| | | | | | | | | | | | | | | | | | | | | - configure/Makefiles: minor adjustments - build-tcc.bat: add -static to gcc options (avoids libgcc_s*.dll dependency with some mingw versions) - tccpe.c/tcctools.c: eliminate MAX_PATH (not available for cross compilers) - tccasm.c: use uint64_t/strtoull in unary() (unsigned long sometimes is only uint32_t, as always on windows) - tccgen.c: Revert (f077d16c) "tccgen: gen_cast: cast FLOAT to DOUBLE" Was a rather experimental, tentative commit, not really necessary and somewhat ugly too. - cleanup recent osx support: - Makefile/libtcc.c: cleanup copy&paste code - tccpp.c: restore deleted function
* tccgen/win32: let __declspec(dllimport) imply externgrischka2017-04-041-134/+127
| | | | | | | | | | | | | | | | | | | | | | | Also, retain storage qualifiers in type_decl, in particular also for function pointers. This allows to get rid of this very early hack in decl() type.t |= (btype.t & VT_STATIC); /* Retain "static". */ which was to fix the case of int main() { static int (*foo)(); ... Also: - missing __declspec(dllimport) is an error now - except if the symbol is "_imp__symbol" - demonstrate export/import of data in the dll example (while 'extern' isn't strictly required with dllimport anymore) - new function 'patch_storage()' replaces 'weaken_symbol()' and 'apply_visibility()' - new function 'update_storage()' applies storage attributes to Elf symbols. - put_extern_sym/2 accepts new pseudo section SECTION_COMMON - add -Wl,-export-all-symbols as alias for -rdynamic - add -Wl,-subsystem=windows for mingw compatibility - redefinition of 'sym' error for initialized global data
* tcc: re-enable correct option -r supportgrischka2017-02-201-53/+86
| | | | | | | | | | | | | | | Forgot about it. It allows to compile several sources (and other .o's) to one single .o file; tcc -r -o all.o f1.c f2.c f3.S o4.o ... Also: - option -fold-struct-init-code removed, no effect anymore - (tcc_)set_environment() moved to tcc.c - win32/lib/(win)crt1 minor fix & add dependency - debug line output for asm (tcc -c -g xxx.S) enabled - configure/Makefiles: x86-64 -> x86_64 changes - README: cleanup
* fixes & cleanupsgrischka2017-02-131-41/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - tccgen.c/tcc.h: allow function declaration after use: int f() { return g(); } int g() { return 1; } may be a warning but not an error see also 76cb1144ef91924c53c57ea71e6f67ce73ce1cc6 - tccgen.c: redundant code related to inline functions removed (functions used anywhere have sym->c set automatically) - tccgen.c: make 32bit llop non-equal test portable (probably not on C67) - dynarray_add: change prototype to possibly avoid aliasing problems or at least warnings - lib/alloca*.S: ".section .note.GNU-stack,"",%progbits" removed (has no effect) - tccpe: set SizeOfCode field (for correct upx decompression) - libtcc.c: fixed alternative -run invocation tcc "-run -lxxx ..." file.c (meant to load the library after file). Also supported now: tcc files ... options ... -run @ arguments ...
* tccgen: yet another nocode_wanted fixgrischka2017-02-121-4/+2
| | | | | | | | | | | Some code in gen_opl was depending on a gvtst label which in nocode_wanted mode is not set. This was causing vstack leaks and crashes with for example long long ll; if (0) return ll - 10 < 0;
* tccgen: factor out gfunc_returngrischka2017-02-081-182/+172
| | | | | | | Also: - on windows i386 and x86-64, structures of size <= 8 are NOT returned in registers if size is not one of 1,2,4,8. - cleanup: put all tv-push/pop/swap/rot into one place
* tccgen: gen_cast: cast FLOAT to DOUBLEgrischka2017-02-051-0/+9
| | | | | ... to avoid precision loss when casting to int, also when saving FLOATs to stack
* Fix some code suppression falloutMichael Matz2016-12-201-3/+16
| | | | | | | | | | Some more subtle issues with code suppression: - outputting asms but not their operand setup is broken - but global asms must always be output - statement expressions are transparent to code suppression - vtop can't be transformed from VT_CMP/VT_JMP when nocode_wanted Also remove .exe files from tests2 if they don't fail.
* i386-gen: fix USE_EBXgrischka2016-12-191-1/+1
| | | | | | | | | | | | | Restore ebx from *ebp because alloca might change esp. Also disable USE_EBX for upcoming release. Actually the benefit is less than one would expect, it appears that tcc can't do much with more than 3 registers except with extensive use of long longs where the disassembly looks much prettier (and shorter also). Also: tccgen/expr_cond() : fix wrong gv/save_regs order
* tests: add memory leak testgrischka2016-12-181-8/+5
| | | | | | | | | | | | | Also ... tcctest.c: - exclude stuff that gcc doesn't compile on windows. libtcc.c/tccpp.c: - use unsigned for memory sizes to avoid printf format warnings - use "file:line: message" to make IDE error parsers happy. tccgen.c: fix typo
* tccgen: nocode_wanted++/--grischka2016-12-181-51/+37
| | | | | uses 'nocode_wanted' as a level couter instead of 'saved_nocode_wanted' everywhere.
* tccgen: fix expr_cond for alt. nocode_wantedgrischka2016-12-181-70/+74
| | | | | making shure that both the active and the passive branches do exacly the same thing.
* tccgen: nocode_wanted alternativelygrischka2016-12-181-92/+52
| | | | | | | | | | | | | | | tccgen.c: remove any 'nocode_wanted' checks, except in - greloca(), disables output elf symbols and relocs - get_reg(), will return just the first suitable reg) - save_regs(), will do nothing Some minor adjustments were made where nocode_wanted is set. xxx-gen.c: disable code output directly where it happens in functions: - g(), output disabled - gjmp(), will do nothing - gtst(), dto.
* 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.