Commit Graph

71 Commits

Author SHA1 Message Date
Ekaitz 7ae03cc19b lib/tests: 44-switch-body-fallthrough-not-default.c: Add test.
This test detects if the fallthrough in a switch statement falls to the
next case (good) or to the default case (bad).

* lib/tests/scaffold/44-switch-body-fallthrough-not-default.c: New file.
* build-aux/check-mescc.sh (mes_tests): Add it.
2023-09-12 11:04:11 +02:00
Ekaitz c989f9c56a lib/tests: 50-compare-rotated-weird.c: Add test for RV reloc
We detected the value in off64 in the test is not -1 as it should but 56
ones. This is because the rotation is applied as unsigned even with the
signed cast. This breaks many things in tcc.

* lib/tests/scaffold/50-compare-rotated-weird.c: New file.
* build-aux/check-mescc.sh (mes_tests): Add it.
2023-09-12 11:04:11 +02:00
Ekaitz b12f56c922 mescc: Initialize missing struct fields to 0.
This is a follow-up to commits
    7a8a2fc517
    mescc: x86_64 support: Refactor to abstracted assembly, add x86_64.

and

    c9ba7a619b
    mescc: Refactor variable declaration.

There was a debug "22" leaking in compile.scm.  It should be a "0".

* module/mescc/compile.scm (init-local): Replace "22" with "0".
* lib/tests/scaffold/7v-struct-initialize-zeroes.c: New test.
* build-aux/check-mescc.sh (tcc_tests): Add it.
(xfail-tests): Remove lib/tests/scaffold/72-typedef-struct-def-local.c.
2023-09-12 11:04:11 +02:00
Janneke Nieuwenhuizen c5fbf9a06c lib/tests: 76-pointer-arithmetic: Cater for RISC-V64.
* lib/tests/scaffold/76-pointer-arithmetic.c (struct
foo)[__riscv_xlen==64]: Add __align.
2023-09-12 11:04:11 +02:00
W. J. van der Laan fa3e83691d lib/tests: Take RISC-V into account in size conditionals.
* lib/tests/scaffold/76-pointer-arithmetic.c (main): Use the right sizes
in the test for RISC-V architectures.
* lib/tests/scaffold/7k-for-each-elem.c (main): Same.
* lib/tests/scaffold/85-sizeof.c: Same.
2023-09-12 11:04:10 +02:00
Janneke Nieuwenhuizen bc4339815f DRAFT test: Add 68-truncate-shift.
* lib/tests/scaffold/68-truncate-shift.c: New file.
* build-aux/check-mescc.sh (mes_tests): Add it.
2023-09-12 11:04:02 +02:00
Andrius Štikonas 08b1e9fefe mescc: Do not overflow M1 64bit immediates.
M1 immediates are limited to 31-bit before they become negative.

* module/mescc/x86_64/as.scm (x86_64:value->r, x86_64:r-cmp-value,
x86_64:r-long-mem-add, x86_64:r-and): Limit M1 immediate to #x80000000.

* lib/tests/scaffold/67-m1-overflow-check.c: New test.
* build-aux/check-mescc.sh (mes_tests): Add it.
2023-09-12 11:04:02 +02:00
Janneke Nieuwenhuizen a4a0d0d66d DRAFT lib: tests: 17-compare-unsigned-le: Add case from 7s-unsigned-compare.
* lib/tests/scaffold/17-compare-unsigned-le.c: Add case from
7s-unsigned-compare; rewrite to avoid gcc-optimize.
2023-08-30 06:17:08 +02:00
Janneke Nieuwenhuizen 37113f1988 DRAFT lib: tests: 17-compare-unsigned-short-le.c: Avoid gcc optimize.
* lib/tests/scaffold/17-compare-unsigned-short-le.c (main): Change
comparison with immediate to comparison with variable.
2023-08-30 06:17:08 +02:00
Janneke Nieuwenhuizen 03179824f8 DRAFT lib: tests: 17-compare-unsigned-char-le.c: Avoid gcc optimize.
* lib/tests/scaffold/17-compare-unsigned-char-le.c (main): Change
comparison with immediate to comparison with variable.
2023-08-30 06:17:08 +02:00
Janneke Nieuwenhuizen b33e3e8b76 squash! lib: tests: Add 17-compare-rotated. 2023-08-30 06:17:08 +02:00
Janneke Nieuwenhuizen 8aace6faae squash! lib: tests: Add 16-cast. 2023-08-30 06:17:08 +02:00
Ekaitz d6f7739bfc lib: tests: Add 17-compare-rotated.
* lib/tests/scaffold/17-compare-rotated.c: Add file.
* build-aux/check-mescc.sh (mes_tests): Add it.
2023-08-29 22:07:10 +02:00
Ekaitz 5128d6c3b4 lib: tests: Add 16-cast.
* lib/tests/scaffold/16-cast.c: Add file.
* build-aux/check-mescc.sh (mes_tests): Add it.
2023-08-29 22:07:10 +02:00
Janneke Nieuwenhuizen 96ad09dbfd lib: tests: 63-struct-cell: Avoid segfault by array overflow with gcc >= 10.
* lib/tests/scaffold/63-struct-cell.c (g_functions]: Use size 3.
2023-08-29 22:07:01 +02:00
Janneke Nieuwenhuizen ab9946d8ef lib/tests: Initialize local variable.
Reuported by Andrius Štikonas <andrius@stikonas.eu> via IRC.

* lib/tests/assert/50-assert.c (main): Initialize local f.
* lib/tests/scaffold/21-char-array.c (main): Likewise.
2023-07-08 15:10:05 +02:00
Jan (janneke) Nieuwenhuizen 074fa78f5e
lib/test: Cater for gcc-12.2.0.
These inexplicably avoid segfaults with gcc-12.2.0.

* lib/tests/posix/50-open-read.c (main)[__GNUC__ > 11]: Use malloc
instead of local allocated string.
* lib/tests/scaffold/7i-struct-struct.c (main)[__GNUC__ > 11]:
Initialize all fields of struct.
* lib/tests/scaffold/t.c (main): Likewise.
2022-09-15 13:56:38 +02:00
Rick Masters fdac9fd3f2
lib: abtol: Fix number digits in hex number conversion.
After a letter based digit, number based digits are off.

* lib/mes/abtol.c (abtol): Reset "m" for number based digit.
* lib/tests/stdlib/70-strtoull.c (main): Test it.
* lib/tests/stdlib/90-strtol.c (main): Likewise.
2022-10-07 11:59:57 +02:00
Jan (janneke) Nieuwenhuizen dbec0c3845
test: Add 60-math-modulo.c.
* lib/tests/scaffold/60-math-modulo.c: New test.
* build-aux/check-mescc.sh (mes_tests): Add it.
2022-09-11 23:34:20 +02:00
Jan (janneke) Nieuwenhuizen 902ed2524a
mescc: Mes C Library: memcmp: bugfix.
* lib/string/memcmp.c (memcmp): Bugfix.
* lib/tests/string/50-memcmp.c: Test it.
* build-aux/check-mescc.sh (TESTS): Add it.
2020-06-06 22:37:30 +02:00
W. J. van der Laan be4514c4de
lib/tests: Pass int to va_arg instead of char.
* lib/tests/scaffold/70-stdarg.c (stdarg1, stdarg2, stdarg3): Pass int
to va_arg instead of char to avoid gcc trap "warning: 'char’ is promoted
to ‘int’ when passed through ‘...’ [enabled by default] (so you should
pass ‘int’ not ‘char’ to ‘va_arg’) if this code is reached, the program
will abort".
2021-05-02 16:56:29 +02:00
Jan (janneke) Nieuwenhuizen 9711ed70ec
tests: Add 70-or-argument.c.
* lib/tests/scaffold/70-or-argument.c: New file.
* build-aux/check-mescc.sh (tcc_tests): Add it.
2021-01-23 08:43:46 +01:00
Jan (janneke) Nieuwenhuizen b531c73590
tests: Add 70-function-modulo.c.
* lib/tests/scaffold/70-function-modulo.c: New file.
* build-aux/check-mescc.sh (tcc_tests): Add it.
2021-01-23 08:43:45 +01:00
Jan (janneke) Nieuwenhuizen 4b194d7bc7
tests: 70-strchr.c: Rewrite for TinyCC.
* lib/tests/string/70-strchr.c (main): Use char* hello for comparison.
Allows for duplication of "hello" string.
2021-01-23 08:43:45 +01:00
Jan (janneke) Nieuwenhuizen bdb1e2ec56
test: scaffold/54-argv.c: Support running with TinyCC.
This fixes running as lib/tests/scaffold/54-argv-i686-unknown-linux-gnu-tcc.

* lib/tests/scaffold/54-argv.c (main): Compare only first 26 characters
of argv[0].
2021-01-23 08:43:45 +01:00
Jan (janneke) Nieuwenhuizen 98965c8807
test: Split-off scaffold/60-math-itoa.c.
* lib/tests/scaffold/60-math.c (main): Move itoa tests to...
* lib/tests/scaffold/60-math-itoa.c: ...this new file.
* build-aux/check-mescc.sh (mes_tests): Add it.
2021-01-23 08:43:43 +01:00
Jan (janneke) Nieuwenhuizen af2353dd23
test: Split-off 36-compare-arithmetic-negative.c.
* lib/tests/scaffold/36-compare-arithmetic.c (main): Move negative
divisions to...
* lib/tests/scaffold/36-compare-arithmetic-negative.c: ...new file here.
* build-aux/check-mescc.sh (mes_tests): Add it.
2021-01-23 08:43:43 +01:00
Jan (janneke) Nieuwenhuizen cd6131bc21
test: ARM: 08-assign.c: Avoid assembly for tcc.
* lib/tests/scaffold/08-assign.c (main)[__arm__ && __TINYC__]: Avoid assembly.
2021-01-23 08:43:42 +01:00
Jan (janneke) Nieuwenhuizen 691d25699c
test: Split-off 50-strcmp-itoa.c
* lib/tests/string/50-strcmp.c (main): Move itoa tests to...
* lib/tests/string/50-strcmp-itoa.c: ...this new file.
* build-aux/check-mescc.sh (mes_tests): Add it.
2021-01-23 08:43:42 +01:00
Jan (janneke) Nieuwenhuizen 13b69f4b9b
tests: Add 70-ternary-arithmetic-argument.c.
* lib/tests/scaffold/70-ternary-arithmetic-argument.c: New file.
* build-aux/check-mescc.sh (tcc_tests, xfail_tests): Add it.
2021-01-23 08:43:41 +01:00
Jan (janneke) Nieuwenhuizen fa4147a284
mescc: Use signed division for x86, x86_64 when appropriate.
This fixes 36-compare-arithmetic.c

* module/mescc/i386/as.scm (i386:r0/r1, i386:r0%r1): Do not reset
signed?.
* module/mescc/x86_64/as.scm (x86_64:r0/r1, x86_64:r0%r1): Likewise.
* lib/tests/scaffold/36-compare-arithmetic.c (main): Use unique exit
value per failure.
2020-10-06 19:53:02 +02:00
Danny Milosavljevic e3aba5d464
test: Make 7l-struct-any-size-array-simple compatible with default ARM gcc.
* lib/tests/scaffold/7l-struct-any-size-array-simple.c: Make "signed"
explicit in signed char types.
2020-08-22 21:01:45 +02:00
Danny Milosavljevic 7e23d98494
test: Make 7r-sign-extend compatible with default ARM gcc.
* lib/tests/scaffold/7r-sign-extend.c: Make "signed" explicit in
signed char types.
2020-08-22 21:01:36 +02:00
Danny Milosavljevic b11510f4da
ntoab: Handle LONG_MIN case.
* lib/mes/ntoab.c (ntoab): Handle LONG_MIN case.
* lib/tests/scaffold/60-math.c (main): Add test for INT_MIN and hex.
2020-06-15 11:26:43 +02:00
Danny Milosavljevic 48ecb2f29e
test: Test signed division.
* lib/tests/scaffold/36-compare-arithmetic.c (main): Test signed division.
2020-06-10 17:04:55 +02:00
Danny Milosavljevic fbc249832c
Prepare tests for ARMv4.
* lib/tests/io/90-stat.c,
lib/tests/scaffold/76-pointer-arithmetic.c,
lib/tests/scaffold/7k-for-each-elem.c,
lib/tests/scaffold/85-sizeof.c: Prepare tests for ARMv4.
2020-06-02 14:30:02 +02:00
Jan Nieuwenhuizen 89945751d9
hurd: Add open.
* include/fcntl.h (O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_APPEND,
O_TRUNC)[__GNU__]: Specialize for GNU.
* lib/gnu/dir-lookup.c: New file.
* lib/stdio/fopen.c (fopen): Use O_RDONLY.
* lib/tests/posix/50-open-read.c (main): Likewise.
* lib/tests/stdio/90-fseek.c (main): Likewise.
* include/gnu/syscall.h (SYS__dir_lookup): New value.
* lib/gnu/_open3.c: New file.
* build-aux/configure-lib.sh (libc_SOURCES): Build them.
2019-12-13 21:52:30 +01:00
Jan Nieuwenhuizen db4a202c6b
hurd: Add _write.
* include/gnu/syscall.h (SYS__io_write): Add enum field.
(_hurd_dtable, _hurd_dtable_size): Declare variable.
(fd_get, fd_write, __io_write, __syscall_put): Declare.
* lib/gnu/hurd-start.c (_hurd_dtable, _hurd_dtable_size): Define
variable.
* lib/gnu/_write.c: New file.
* lib/gnu/fd-get.c (fd_get): New file.
* lib/gnu/fd-write.c (fd_write): New file.
* lib/gnu/io-write.c: New file.
* lib/gnu/syscall.c (__syscall_put): New function.
* build-aux/cofnigure-lib.sh (libc_mini_SOURCES): Add write sources.
* lib/tests/mes/30-oputs.c (main): Update.
* lib/tests/mes/30-oputs.stdout: New file.
* lib/tests/mes/30-eputs.c: New test.
* lib/tests/mes/30-eputs.stderr: New file.
* build-aux/check-mescc.sh (TESTS): Add it.
2019-12-13 21:52:30 +01:00
Jan Nieuwenhuizen 784838e368
hurd: Initial support.
This adds minimal Hurd support by implementing the _exit function.

* AUTHORS: Update.
* .gitignore: Ignore a.out, core, .config.
* include/sys/wait.h (W_EXITCODE): New define.
* lib/gnu/x86-mes-gcc/crt1.c: New file.
* lib/gnu/x86-mes-gcc/mini.c: New file.
* lib/gnu/hurd-start.c: New file.
* lib/gnu/_exit.c: New file.
* include/gnu/syscall.h: New file.
* include/gnu/hurd.h: New file.
* lib/gnu/_exit.c: New file.
* lib/gnu/exec-startup-get-data.c: New file.
* lib/gnu/hurd-start.c: New file.
* lib/gnu/proc-mark-exit.c: New file.
* lib/gnu/syscall.c: New file.
* lib/gnu/task-get-special-port.c: New file.
* lib/gnu/task-terminate.c: New file.
* lib/gnu/vm-statistics.c: New file.
* build-aux/configure-lib.sh (libc_mini_SOURCES): Add Hurd sources.
* build-aux/build.sh.in (CPPFLAGS): Add lib to includes, to find linux
crt1.c.
* build-aux/test-c.sh: Always use at least -l c+mini for GNU.
* lib/tests/scaffold/30-exit-42.exit: New file.
* lib/tests/scaffold/30-exit-42.c: New test.
* build-aux/check-mescc.sh (TESTS): Add it.
* lib/tests/scaffold/30-exit-0.c (main): Move from 00-exit-0.c; Rewrite,
use _exit.
* include/gnu/hurd-types.h: Import from GNU C Library.
* include/mach/mach-init.h: Likewise.
* lib/mach/mach-init.c: Likewise.
* lib/mach/mach_host_self.S: Likewise.
* lib/mach/mach_msg_trap.S: Likewise.
* lib/mach/mach_reply_port.S: Likewise.
* lib/mach/mach_task_self.S: Likewise.
* lib/mach/mach_thread_self.S: Likewise.
* lib/mach/msg.c: Likewise.
2019-12-13 21:52:29 +01:00
Jan Nieuwenhuizen 3de6450117
test: 90-abtod: Remove printf dependency. Fixes gcc.
* lib/tests/mes/90-abtod.stdout: Remove.
* lib/tests/mes/90-abtod.c (main): Remove printf.
2019-12-02 10:00:03 +01:00
Jan Nieuwenhuizen 35c97baaef
test: 90-readdir: Remove qsort dependency. Fixes tmpfs failures.
* lib/tests/dirent/90-readdir.c (check_seen): New function.
(main): Use it instead of qsort.
(qsort_strcmp): Remove.
2019-12-01 23:58:48 +01:00
Danny Milosavljevic 01ae1994ed
Fix dtoab.
* lib/mes/dtoab.c (dtoab): Fix it.
* lib/tests/mes/90-dtoab.c (main): Fix test.
* build-aux/check-mescc.sh (XFAIL_TESTS: Remove it.
2019-08-27 00:43:37 +02:00
Danny Milosavljevic abc0809bfa
Add missing #include.
* lib/tests/mes/90-abtod.c (main): Add missing #include.
2019-08-27 04:32:02 +02:00
Jan Nieuwenhuizen fd1109a25f
mescc: Mes C Library: vfprintf, vsnprintf: Pad floats with space.
* lib/stdio/vfprintf.c (vfprintf): Pad floats with space.
* lib/stdio/vsnprintf.c (vsnprintf): Pad floats with space.
* lib/tests/stdio/90-sprintf.c: Test it.
2019-09-01 22:18:00 +02:00
Jan Nieuwenhuizen f3154aabe4
mescc: Mes C Library: Support GNU Awk: Add dtoab, %f in vfprintf, vsnprintf.
* include/libmes.h (dtoab): Declare.
* lib/mes/ntoab.c (ntoab): Update.
* lib/mes/dtoab.c: New file.
* build-aux/configure-lib.sh (libmes_SOURCES, libc_tcc_SOURCES): Add
it.
* lib/tests/mes/90-dtoab.c: Test it.
* lib/tests/stdio/90-sprintf.c: Test it.
* build-aux/check-mescc.sh (tests): Run it, against...
* lib/tests/mes/90-dtoab.stdout: ...baseline.
* lib/stdio/vfprintf.c (vfprintf): Support %f, even more naive support
for %e, %E, %g, %G.
* lib/stdio/vsnprintf.c (vsnprintf): Likewise.
2020-01-12 18:42:25 +01:00
Jan Nieuwenhuizen 742e88abd5
mescc: Mes C Library: Support GNU Awk: Add abtod, implementing strtod.
* include/libmes.h (abtod): Declare.
* lib/mes/abtod.c: New file.
* build-aux/configure-lib.sh (libmes_SOURCES, libc_tcc_SOURCES): Add
it.
* lib/mes/abtol.c: Update.
* lib/stdlib/strtod.c: Use it to implement; move from stub/strtod.
* lib/tests/mes/90-abtod.c: Test it.
* lib/tests/mes/90-abtod.stdout: Baseline.
* build-aux/check-mescc.sh (tests): Run it.
2019-06-25 12:51:44 +02:00
Jan Nieuwenhuizen 4e6a3ce846
mescc: Mes C Library: Support GNU Tar: Add execlp.
* lib/posix/execl.c (vexec): New function.
(execl): Use it.
* lib/posix/execlp.c: New file.
* build-aux/configure-lib.sh (libc_tcc_SOURCES): Add it.
* lib/libc+gnu.c: Include it.
* include/unistd.h (execlp): Declare.
* lib/tests/posix/90-execlp.c: New file.
* lib/tests/posix/90-execlp.stdout: New file.
* build-aux/check-mescc.sh: Test it.
2019-06-10 00:56:42 +02:00
Danny Milosavljevic 15a39f0efe
Add missing #include.
* lib/tests/scaffold/55-char-array.c: Add missing #include.
2019-09-09 16:04:15 +02:00
Danny Milosavljevic e2dfaef89e
Add missing #include.
* lib/tests/io/90-stat.c: Add missing #include.
2019-09-09 16:04:15 +02:00
Danny Milosavljevic c7d050c0cd
tests: Fail early on nonexistent file.
* lib/tests/io/90-stat.c (main): Fail early on nonexistent file.
2019-09-09 16:04:13 +02:00