aboutsummaryrefslogtreecommitdiff
path: root/tccgen.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix type parsingMichael Matz2016-03-241-6/+9
| | | | | | the check on incomplete struct/union/enum types was too early, disallowing mixed specifiers and qualifiers. Simply rely on the size (->c) field for that. See testcases.
* Keep lvalue category on structs when evaluating ternary operatorVlad Vissoultchev2016-03-131-4/+17
|
* tccgen.c: Fix flex array members some moreMichael Matz2016-03-111-2/+6
| | | | Last fix didn't work for function f1int in the added testcase.
* tccgen.c: off by one in flexible array membersHenry Kroll III2016-03-101-1/+1
| | | | tccgen.c: fix fexible array member breaking struct alignment
* tccgen.c: In parse_btype, handle type qualifiers applied to arrays.Edmund Grimley Evans2016-01-111-14/+25
| | | | Also add some test cases in tests/tests2/39_typedef.c.
* Change the way struct CStrings are handled.Edmund Grimley Evans2015-11-261-14/+12
| | | | | | | | | A CString used to be copied into a token string, which is an int array. On a 64-bit architecture the pointers were misaligned, so ASan gave lots of warnings. On a 64-bit architecture that required memory accesses to be correctly aligned it would not work at all. The CString is now included in CValue instead.
* tccgen.c: Give error if statement expression found when const wanted.Edmund Grimley Evans2015-11-261-6/+2
| | | | | | | | | | | | | | | | Some test cases: #define SE ({ switch (0) { } 0; }) // Should give error: int x = SE; void f(void) { static int x = SE; } void f(void) { enum e { a = SE }; } void f(void) { switch (0) { case SE: break; } } // Correct: int f(void) { return SE; } int f(void) { return sizeof(SE); }
* tccgen.c: Try to make sizeof(!x) work.Edmund Grimley Evans2015-11-221-3/+1
| | | | tests/tests2/27_sizeof.*: Add test.
* tccgen.c: Bug fix for 992cbda and 3ff77a1: set nocode_wanted.Edmund Grimley Evans2015-11-211-8/+26
| | | | tests/tests2/78_vla_label.*: Add test.
* Improve constant propagation with "&&" and "||".Edmund Grimley Evans2015-11-201-50/+53
|
* tccgen: asm_label cleanupgrischka2015-11-201-39/+30
| | | | | | | - avoid memory allocation by using its (int) token number - avoid additional function parameter by using Attribute Also: fix some strange looking error messages
* tccgen.c: Recognise constant expressions with conditional operator.Edmund Grimley Evans2015-11-201-7/+7
| | | | tests/tests2/78_vla_label.c: Check that int a[1 ? 1 : 1] is not a VLA.
* tccgen.c: In parse_btype, handle typedef types with added type qualifiers.Edmund Grimley Evans2015-11-191-1/+11
| | | | | | | | | | | | | | | | | | In a case like typedef int T[1]; const T x; we must make a copy of the typedef type so that we can add the type qualifiers to it. The following code used to give error: incompatible types for redefinition of 'f' typedef int T[1]; void f(const int [1]); void f(const T);
* tccgen.c: Improvements to type_to_str (only used for error messages).Edmund Grimley Evans2015-11-191-0/+9
| | | | | 1. Handle array types. 2. Print the type qualifiers of pointers.
* tccgen.c: Avoid undefined behaviour in constant propagation.Edmund Grimley Evans2015-11-171-31/+38
|
* Merge the integer members of union CValue into "uint64_t i".Edmund Grimley Evans2015-11-171-65/+61
|
* tccgen.c: Use memmove for struct assignment: dest and src may be equal.Edmund Grimley Evans2015-11-041-1/+2
|
* tccgen.c: Fix memory leak involving asm_label.Edmund Grimley Evans2015-11-041-5/+9
|
* tccgen.c: Remove undefined shift of negative signed value.Edmund Grimley Evans2015-10-151-3/+4
|
* a number as a field name (part 2)seyko2015-09-251-0/+2
| | | | | | | | | | | | | | | | don't crash a test program: ================ typedef struct X { int len; } X; #define init(s,len) s.len = len; int main(void) { X myX; init(myX,10); return 0; } ================ After a patch: error: field name expected
* a number as a field nameseyko2015-09-251-2/+4
| | | | | | | | | | | | | | | | a test program: ======== typedef struct X { int len; } X; int main(void) { X myX; myX.10 = 10; return 0; } ======== Error message before a patch: error: ';' expected (got "(null)") After a patch: error: field name expected
* Revert "fix-mixed-struct (patch by Pip Cet)"gus knight2015-07-291-81/+5
| | | | This reverts commit 4e04f67c94c97b4f28a4d73759a0ad38fb3a10f7. Requested by grischka.
* Revert all of my changes to directories & codingstyle.gus knight2015-07-291-0/+6463
|
* Reorganize the source tree.gus knight2015-07-271-6463/+0
| | | | | | | | | | * Documentation is now in "docs". * Source code is now in "src". * Misc. fixes here and there so that everything still works. I think I got everything in this commit, but I only tested this on Linux (Make) and Windows (CMake), so I might've messed something up on other platforms...
* Clean up lots of rogue tabs.gus knight2015-07-271-169/+169
| | | | | | Still some more tabs to be taken care of. arm-gen.c and tcccoff.c have so many style issues that I'm just going to throw clang-format at them.
* Trim trailing spaces everywhere.gus knight2015-07-271-110/+110
|
* fix-mixed-struct (patch by Pip Cet)seyko2015-05-141-5/+81
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Jsut for testing. It works for me (don't break anything) Small fixes for x86_64-gen.c in "tccpp: fix issues, add tests" are dropped in flavor of this patch. Pip Cet: Okay, here's a first patch that fixes the problem (but I've found another bug, yet unfixed, in the process), though it's not particularly pretty code (I tried hard to keep the changes to the minimum necessary). If we decide to actually get rid of VT_QLONG and VT_QFLOAT (please, can we?), there are some further simplifications in tccgen.c that might offset some of the cost of this patch. The idea is that an integer is no longer enough to describe how an argument is stored in registers. There are a number of possibilities (none, integer register, two integer registers, float register, two float registers, integer register plus float register, float register plus integer register), and instead of enumerating them I've introduced a RegArgs type that stores the offsets for each of our registers (for the other architectures, it's simply an int specifying the number of registers). If someone strongly prefers an enum, we could do that instead, but I believe this is a place where keeping things general is worth it, because this way it should be doable to add SSE or AVX support. There is one line in the patch that looks suspicious: } else { addr = (addr + align - 1) & -align; param_addr = addr; addr += size; - sse_param_index += reg_count; } break; However, this actually fixes one half of a bug we have when calling a function with eight double arguments "interrupted" by a two-double structure after the seventh double argument: f(double,double,double,double,double,double,double,struct { double x,y; },double); In this case, the last argument should be passed in %xmm7. This patch fixes the problem in gfunc_prolog, but not the corresponding problem in gfunc_call, which I'll try tackling next.
* tccpp: fix issues, add testsgrischka2015-05-091-25/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * fix some macro expansion issues * add some pp tests in tests/pp * improved tcc -E output for better diff'ability * remove -dD feature (quirky code, exotic feature, didn't work well) Based partially on ideas / researches from PipCet Some issues remain with VA_ARGS macros (if used in a rather tricky way). Also, to keep it simple, the pp doesn't automtically add any extra spaces to separate tokens which otherwise would form wrong tokens if re-read from tcc -E output (such as '+' '=') GCC does that, other compilers don't. * cleanups - #line 01 "file" / # 01 "file" processing - #pragma comment(lib,"foo") - tcc -E: forward some pragmas to output (pack, comment(lib)) - fix macro parameter list parsing mess from a3fc54345949535524d01319e1ca6378b7c2c201 a715d7143d9d17da17e67fec6af1c01409a71a31 (some coffee might help, next time ;) - introduce TOK_PPSTR - to have character constants as written in the file (similar to TOK_PPNUM) - allow '\' appear in macros - new functions begin/end_macro to: - fix switching macro levels during expansion - allow unget_tok to unget more than one tok - slight speedup by using bitflags in isidnum_table Also: - x86_64.c : fix decl after statements - i386-gen,c : fix a vstack leak with VLA on windows - configure/Makefile : build on windows (MSYS) was broken - tcc_warning: fflush stderr to keep output order (win32)
* a lot simpler VLA codeseyko2015-05-041-80/+33
| | | | | | | | Author: Philip <pipcet@gmail.com> Our VLA code can be made a lot simpler (simple enough for even me to understand it) by giving up on the optimization idea, which is very tempting. There's a patch to do that attached, feel free to test and commit it if you like. (It passes all the tests, at least
* fix vstack leakPhilip2015-04-291-1/+2
| | | | | | | | I think this code only affects the ARM EABI target, and only when returning small structures that might be unaligned. However, it was both leaking vstack entries and failing to achieve what I think is its purpose, to ensure the sret argument would be aligned properly. Both issues fixed.
* VLA fix: save stack pointer right after modificationPhilip2015-04-281-6/+9
| | | | | | | | | | | | | | | | This patch disables the optimization of saving stack pointers lazily, which didn't fully take into account that control flow might not reach the stack-saving instructions. I've decided to leave in the extra calls to vla_sp_save() in case anyone wants to restore this optimization. Tests added and enabled. There are two remaining bugs: VLA variables can be modified, and jumping into the scope of a declared VLA will cause a segfault rather than a compiler error. Both of these do not affect correct C code, but should be fixed at some point. Once VLA variables have been made properly immutable, we can share them with the saved stack pointer and save stack and instructions.
* fix VLA/continue issuePhilip2015-04-271-0/+23
| | | | | | | | | | | | | | | | | | as reported in http://lists.nongnu.org/archive/html/tinycc-devel/2015-04/msg00131.html. Note that this is one of two separate VLA bugs: A. labels aren't reached by program execution, so the stack pointer is never saved B. continue doesn't restore the stack pointer as goto does This fixes only B. I'm not sure whether the same issue applies to break as well as continue. Add a test case, but disable tests #78 and #79 for now as they're not fully fixed until the issue described in http://lists.nongnu.org/archive/html/tinycc-devel/2015-04/msg00110.html is resolved.
* Revert "* and #pragma pop_macro("macro_name")"grischka2015-04-231-0/+1
| | | | | | | | | | | | - pop_macro incorrect with initially undefined macro - horrible implementation (tcc_open_bf) - crashes eventually (abuse of Sym->prev_tok) - the (unrelated) asm_label part is the opposite of a fix (Despite of its name this variable has nothing to do with the built-in assembler) This reverts commit 0c8447db7970813292a8be74ee50e49091be5d15.
* * and #pragma pop_macro("macro_name")seyko2015-04-211-1/+0
| | | | | | | | | | * give warning if pragma is unknown for tcc * don't free asm_label in sym_free(), it's a job of the asm_free_labels(). The above pragmas are used in the mingw headers. Thise pragmas are implemented in gcc-4.5+ and current clang.
* option to use an old algorithm of the array in struct initializationseyko2015-04-101-4/+31
| | | | | | This is for a case when no '{' is used in the initialization code. An option name is -fold-struct-init-code. A linux 2.4.26 can't find initrd when compiled with a new algorithm.
* a bounds checking code for the ARCH=x86_64seyko2015-04-101-2/+17
|
* fix the bug #31403: parser bug in structureseyko2015-04-101-3/+16
| | | | | | - a warning: unnamed struct/union that defines no instances - allow a nested named struct declaration w/o identifier only when option -fms-extensions is used
* make a bound checking more compatible with Windows 64seyko2015-03-261-4/+4
| | | | | | On Linux 32: sizeof(long)=32 == sizeof(void *)=32 on Linux 64: sizeof(long)=64 == sizeof(void *)=64 on Windows 64: sizeof(long)=32 != sizeof(void *)=64
* A right fix for the array in struct initialization w/o '{'seyko2015-03-231-20/+9
| | | | | Parse a type if there is only one '(' before a type token. Otherwise a recursion will perform a job.
* Revert of the commit: fix for the array in struct initialization w/o '{', case 2seyko2015-03-231-16/+9
| | | | A right solution for this problem will follow.
* restore a linux 2.4.26 kernel compilation (commit 5bcc3eed7b93 correction)seyko2015-03-201-1/+5
| | | | | | | | The following check in tccgen.c is removed if (nocode_wanted) tcc_error("statement expression in global scope"); This check is introduced in commit 5bcc3eed7b93 and breaks compilation of the linux 2.4.26 kernel.
* tccgen.c: (!nocode_wanted) -> (nocode_wanted) in arm64 part.Edmund Grimley Evans2015-03-101-2/+2
|
* Add some missing nocode_wanted guardThomas Preud'homme2015-03-101-16/+27
| | | | | | int i = i++ causes a segfault because of missing guard. Looking recursively at all backend functions called from middle end several more guard appeared to be missing.
* Remove incorrect commentMichael Matz2015-03-091-2/+0
| | | | Not the code was confused, I was :)
* Fix stack overwrite on structure returnMichael Matz2015-03-091-8/+12
| | | | | | | | | The common code to move a returned structure packed into registers into memory on the caller side didn't take the register size into account when allocating local storage, so sometimes that lead to stack overwrites (e.g. in 73_arm64.c), on x86_64. This fixes it by generally making gfunc_sret also return the register size.
* arm64: Implement __clear_cache.Edmund Grimley Evans2015-03-081-0/+12
| | | | | | __clear_cache is defined in lib-arm64.c with a single call to __arm64_clear_cache, which is the real built-in function and is turned into inline assembler by gen_clear_cache in arm64-gen.c
* tccgen.c: Optimise 0<<x, 0>>x, -1>>x, x&0, x*0, x|-1, x%1.Edmund Grimley Evans2015-03-071-10/+25
| | | | | | | | | More precisely, treat (0 << x) and so on as constant expressions, but not if const_wanted as we do not want to allow "case (x*0):", ... Do not optimise (0 / x) and (0 % x) here as x might be zero, though for an architecture that does not generate an exception for division by zero the back end might choose to optimise those.
* fix for the array in struct initialization w/o '{', case 2seyko2015-03-071-9/+16
| | | | | | | | | | | | | | a test program: struct { int a[2], b[2]; } cases[] = { { ((int)0), (((int)0)) }, ((int)0), (((int)0)) /* error: ',' expected (got ")") */ }; int main() { return 0; } This commit allow to skip ')' in the decl_initializer() and to see ','
* Add __builtin_return_address.Edmund Grimley Evans2015-03-061-1/+13
| | | | | | Implementation is mostly shared with __builtin_frame_address. It seems to work on arm64, i386 and x86_64. It may need to be adapted for other targets.
* fixing decl_initializer() for size_only: don't eat ')'seyko2015-03-051-2/+8
| | | | | | | | | | a test program: struct { int c[1]; } s1[] = { (int)0 }; /* OK */ struct { int c[1]; } s2[] = { { ((int)0) } }; /* OK */ struct { int c[1]; } s3[] = { 0 }; /* OK */ struct { int c[1]; } sx[] = { ((int)0) }; /* error: ')' expected (got "}") */ int main() { return 0; }