aboutsummaryrefslogtreecommitdiff
path: root/tests/tcctest.c
Commit message (Collapse)AuthorAgeFilesLines
* opt: Start optimizing dead code a bitMichael Matz2016-12-151-0/+27
| | | | | | | 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.
* Fix aliases on 64 bitMichael Matz2016-12-151-0/+1
| | | | Use correct width ELF structure.
* Fix sizeof(char[a])Michael Matz2016-12-151-0/+10
| | | | | 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/+10
| | | | | was incorrectly treated as constant because the vpop removed all traces of non-constness.
* tccasm: Support refs to anon symbols from asmMichael Matz2016-12-151-0/+23
| | | | | | | This happens when e.g. string constants (or other static data) are passed as operands to inline asm as immediates. The produced symbol ref wouldn't be found. So tighten the connection between C and asm-local symbol table even more.
* Fix enum bitfields passed to stdarg functionsMichael Matz2016-12-151-0/+5
| | | | | 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-0/+10
| | | | Use this fact in some foldings of comparisons. See testcase.
* Fix access-after-free with statement expressionsMichael Matz2016-12-151-0/+46
| | | | | | | | | | | | 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.
* tccpp: Allow computed include like 42.hMichael Matz2016-12-151-3/+18
| | | | | | The include directive needs to be parsed as pp-tokens, not as token (i.e. no conversion to TOK_STR or TOK_NUM). Also fix parsing computed includes using quoted strings.
* x86-asm: Correctly infer register size for boolsMichael Matz2016-12-151-0/+10
| | | | | | Register operands of type _Bool weren't correctly getting the 8-bit sized registers (but rather used the default 32-bit ones).
* x86-64: Allow loads from some structs/unionsMichael Matz2016-12-151-0/+6
| | | | | | GCC allows register loads for asms based on type mode, and correctly sized structs/union have an allowed mode (basically 1,2,4,8 sized aggregates).
* tccasm: Lookup C symbols from ASM blocksMichael Matz2016-12-151-0/+28
| | | | | It's now possible to use symbols defined in C code to be used from later inline asm blocks. See testcase.
* enums and ints are compatibleMichael Matz2016-12-151-1/+1
| | | | | | | 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/+2
|
* inline-asm: Accept "flags" clobberMichael Matz2016-12-151-1/+1
|
* Support attribute between double pointer starsMichael Matz2016-12-151-0/+7
| | | | "int * __attribute__((something)) *" is supported by GCC.
* Fix function to pointer conversionMichael Matz2016-12-151-0/+7
| | | | | | | | 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/+14
| | | | | | | | | | | 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).
* tccpp: Implement __BASE_FILE__ macroMichael Matz2016-12-151-0/+7
| | | | | Like __FILE__ but always refers to the command line file name also from inside headers.
* Implement __builtin_choose_exprMichael Matz2016-12-151-0/+13
| | | | Follows GCC implementation.
* Fix parsing attributes for struct declsMichael Matz2016-12-151-0/+33
| | | | | | | | | | | 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-0/+7
| | | | Those should use long or long long type, and generate a 64bit reloc.
* inline asm: Accept 'p' constraint and 'P' template modMichael Matz2016-12-151-0/+9
| | | | | 'p' is conservatively the same as 'r' and 'P' as template modifier can be ignored in TCC.
* Accept empty struct member declsMichael Matz2016-12-151-0/+5
| | | | | | | struct S { /*nothing*/; int a; }; is an acceptable struct declaration, there may be stray semicolons in the member list.
* x86-asm: Accept 'q' modifierMichael Matz2016-12-151-0/+11
| | | | In inline extended asm '%q1' refers to the 64bit register of operand 1.
* tests: add .so/.dll creation testgrischka2016-12-151-9/+0
| | | | | Also remove bitfield test from tcctest.c because gcc versions don't agree among each other.
* Implement gcc bitfield algorithm; add -mms-bitfieldsDavid Mertens2016-11-281-0/+9
|
* x86_64-asm: =m operand fixesgrischka2016-11-201-3/+25
| | | | | | | | | | | | | | | | | | | | | | The problem was with tcctest.c: unsigned set; __asm__("btsl %1,%0" : "=m"(set) : "Ir"(20) : "cc"); when with tcc compiled with the HAVE_SELINUX option, run with tcc -run, it would use large addresses far beyond the 32bits range when tcc did not use the pc-relative mode for accessing 'set' in global data memory. In fact the assembler did not know about %rip at all. Changes: - memory operands use (%rax) not (%eax) - conversion from VT_LLOCAL: use type VT_PTR - support 'k' modifier - support %rip register - support X(%rip) pc-relative addresses The test in tcctest.c is from Michael Matz.
* tccpp : "tcc -E -P" : suppress empty linesgrischka2016-10-091-0/+4
| | | | | | | | | 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: arm/i386: save_reg_upstackgrischka2016-10-041-4/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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)
* switch: fix label sortingPavlas, Zdenek2016-10-031-0/+3
|
* Incorrect function call code on ARMv6Balazs Kezes2016-10-011-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On 2016-08-11 09:24 +0100, Balazs Kezes wrote: > I think it's just that that copy_params() never restores the spilled > registers. Maybe it needs some extra code at the end to see if any > parameters have been spilled to stack and then restore them? I've spent some time on this and I've found an alternative solution. Although I'm not entirely sure about it but I've attached a patch nevertheless. And while poking at that I've found another problem affecting the unsigned long long division on arm and I've attached a patch for that too. More details in the patches themselves. Please review and consider them for merging! Thank you! -- Balazs [PATCH 1/2] Fix slow unsigned long long division on ARM The macro AEABI_UXDIVMOD expands to this bit: #define AEABI_UXDIVMOD(name,type, rettype, typemacro) \ ... while (num >= den) { \ ... while ((q << 1) * den <= num && q * den <= typemacro ## _MAX / 2) \ q <<= 1; \ ... With the current ULONG_MAX version the inner loop goes only until 4 billion so the outer loop will progress very slowly if num is large. With ULLONG_MAX the inner loop works as expected. The current version is probably a result of a typo. The following bash snippet demonstrates the bug: $ uname -a Linux eper 4.4.16-2-ARCH #1 Wed Aug 10 20:03:13 MDT 2016 armv6l GNU/Linux $ cat div.c int printf(const char *, ...); int main(void) { unsigned long long num, denom; num = 12345678901234567ULL; denom = 7; printf("%lld\n", num / denom); return 0; } $ time tcc -run div.c 1763668414462081 real 0m16.291s user 0m15.860s sys 0m0.020s [PATCH 2/2] Fix long long dereference during argument passing on ARMv6 For some reason the code spills the register to the stack. copy_params in arm-gen.c doesn't expect this so bad code is generated. It's not entirely clear why the saving part is necessary. It was added in commit 59c35638 with the comment "fixed long long code gen bug" with no further clarification. Given that tcctest.c passes without this, maybe it's no longer needed? Let's remove it. Also add a new testcase just for this. After I've managed to make the tests compile on a raspberry pi, I get the following diff without this patch: --- test.ref 2016-08-22 22:12:43.380000000 +0100 +++ test.out3 2016-08-22 22:12:49.990000000 +0100 @@ -499,7 +499,7 @@ 2 1 0 1 0 4886718345 -shift: 9 9 9312 +shift: 291 291 291 shiftc: 36 36 2328 shiftc: 0 0 9998683865088 manyarg_test: More discussion on this thread: https://lists.nongnu.org/archive/html/tinycc-devel/2016-08/msg00004.html
* win64: fix va_arggrischka2016-07-101-0/+9
| | | | | | | | | | | fixes 5c35ba66c5ade4713bbd9c005e66889f6d7db293 Implementation was consistent within tcc but incompatible with the ABI (for example library functions vprintf etc) Also: - tccpp.c/get_tok_str() : avoid "unknown format "%llu" warning - x86_64_gen.c/gen_vla_alloc() : fix vstack leak
* x86-64: Run asmtest as wellMichael Matz2016-05-111-13/+27
| | | | | This fixes and activates the asm test that's part of tcctest.c also on x86-64, requiring a small fix for the 'm' constraint.
* tccgen: scopes levels for local symbols (update 1)grischka2016-05-051-0/+2
| | | | | | | Catch top level redeclarations too. Also fix mistakes in tcctest.c and the tcc sources (win32) showing up now.
* Fix assignment to/from volatile typesMichael Matz2016-03-261-0/+11
| | | | | | | | | Code like this was broken: char volatile vi = i; See testcase, happens in ideosyncratic legacy code sprinkling volatile all over.
* Fix tokenization of TOK_DOTSMichael Matz2016-03-241-0/+5
| | | | | We really need to use PEEKC during tokenization so as to skip line continuations automatically.
* tests/tcctest.c: Fix up format strings.Edmund Grimley Evans2015-11-041-28/+28
|
* Revert all of my changes to directories & codingstyle.gus knight2015-07-291-58/+58
|
* Trim trailing spaces everywhere.gus knight2015-07-271-58/+58
|
* tccpp: fix issues, add testsgrischka2015-05-091-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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)
* Disable floating-point test for ARM soft-floatseyko2015-03-031-0/+2
| | | | | | | | | | | From: Matteo Cypriani <mcy@lm7.fr> Date: Fri, 5 Sep 2014 23:22:56 -0400 Subject: Disable floating-point test for ARM soft-float tcc is not yet capable of doing softfloat floating-point operations on ARM, therefore we disable this test for these platforms. Note that tcc displays a warning to warn ARM users about this limitation (debian)
* tests/tcctest.c: Test COMPAT_TYPE(char *, signed char *).Edmund Grimley Evans2015-02-241-0/+2
|
* Corrected spelling mistakes in comments and stringsVincent Lefevre2014-04-071-1/+1
|
* arm: Provide alloca()Michael Matz2014-04-051-2/+2
| | | | | | This provides a simple implementation of alloca for ARM (and enables the associated testcase). As tcc for ARM doesn't contain an assembler, we'll have to resort using gcc for compiling it.
* Fix and extend *FCAST test in tcctest.cThomas Preud'homme2014-02-051-5/+8
| | | | | | | Result of float to unsigned integer conversion is undefined if float is negative. This commit take the absolute value of the float before doing the conversion to unsigned integer and add more float to integer conversion test.
* Don't perform builtin_frame_address on ARMThomas Preud'homme2014-02-031-2/+3
|
* Test long long to float conversionsThomas Preud'homme2014-02-011-0/+8
|
* tcctest: One more signed zero testMichael Matz2014-01-121-0/+6
| | | | This also checks that -(-0.0) is +0.0.