scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit 70da2bb8081e70c1ee0f2d9a90104356b61e6b9a
parent 69a6dd3cdb185af347d93e03f82e9f303575843f
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Fri,  8 May 2026 09:57:17 +0200

Merge remote-tracking branch 'origin/master'

Diffstat:
MMakefile | 2+-
Mscripts/rules.mk | 1+
Msrc/cmd/Makefile | 2+-
Msrc/cmd/scc-objdump/Makefile | 2+-
Msrc/libc/stdio/vsprintf.c | 12+++---------
Mtests/cc/execute/0025-string.c | 2+-
Mtests/cc/execute/0041-queen.c | 2+-
Mtests/cc/execute/0140-int_fold.c | 2--
Mtests/cc/execute/0270-union.c | 1-
Mtests/libc/execute/.gitignore | 2++
Mtests/libc/execute/0096-div.c | 6------
Atests/libc/execute/0097-fops.c | 39+++++++++++++++++++++++++++++++++++++++
Atests/libc/execute/0098-tmpfil.c | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtests/libc/execute/libc-tests.lst | 2++
14 files changed, 127 insertions(+), 23 deletions(-)

diff --git a/Makefile b/Makefile @@ -11,7 +11,7 @@ deps: scripts/scc-make +@$(SCCMAKE) dep touch $@;\ -all dep tests install uninstall: scripts/scc-make check_config FORCE +coverage all dep tests install uninstall: scripts/scc-make check_config FORCE +@$(SCCMAKE) -f main.mk $@ check_config: scripts/scc-make FORCE diff --git a/scripts/rules.mk b/scripts/rules.mk @@ -33,6 +33,7 @@ SCC_AR = $(BINDIR)/scc-ar # library dependences helpers LIBMACH = $(LIBDIR)/scc/libmach.a LIBSCC = $(LIBDIR)/scc/libscc.a +LIBSCC_DRIVER = $(LIBDIR)/scc/libscc-$(DRIVER).a # Include configuration definitions include $(BUILDDIR)/conf/$(CONF).mk diff --git a/src/cmd/Makefile b/src/cmd/Makefile @@ -24,4 +24,4 @@ MORE_LDLIBS = -lmach -lscc -lscc-$(DRIVER) all: $(TARGET) $(DIRS) @cp $(TARGET) $(BINDIR) -$(TARGET): $(LIBMACH) $(LIBSCC) $(LIBSCC-DRIVER) +$(TARGET): $(LIBMACH) $(LIBSCC) $(LIBSCC_DRIVER) diff --git a/src/cmd/scc-objdump/Makefile b/src/cmd/scc-objdump/Makefile @@ -13,6 +13,6 @@ MORE_LDLIBS = -lmach -lscc -lscc-$(DRIVER) all: $(TARGET) -scc-objdump: $(OBJS) $(LIBMACH) $(LIBSCC) $(LIBSCC-DRIVER) +scc-objdump: $(OBJS) $(LIBMACH) $(LIBSCC) $(LIBSCC_DRIVER) $(CC) $(PROJ_LDFLAGS) $(OBJS) $(PROJ_LDLIBS) -o $@ cp $@ $(BINDIR) diff --git a/src/libc/stdio/vsprintf.c b/src/libc/stdio/vsprintf.c @@ -7,13 +7,7 @@ int vsprintf(char *restrict s, const char *restrict fmt, va_list va) { - /* - * we used to use SIZE_MAX here, but that is just - * wrong because we build a rp pointer that in that - * case it is just wp - 1 by definition. As it - * is impossible to span an object further than - * the end of the memory space we can use the number - * of bytes until the end of the address space. - */ - return vsnprintf(s, (char *)-1 - s, fmt, va); + uintptr_t addr = (uintptr_t) s; + + return vsnprintf(s, UINTPTR_MAX - addr, fmt, va); } diff --git a/tests/cc/execute/0025-string.c b/tests/cc/execute/0025-string.c @@ -1,4 +1,4 @@ -int strlen(char *); +#include <string.h> int main() diff --git a/tests/cc/execute/0041-queen.c b/tests/cc/execute/0041-queen.c @@ -1,4 +1,4 @@ -int *calloc(int, int); +#include <stdlib.h> int N; int *t; diff --git a/tests/cc/execute/0140-int_fold.c b/tests/cc/execute/0140-int_fold.c @@ -8,8 +8,6 @@ main(void) i = 3 * 6; i = 10 / 5; i = 10 % 5; - i = i % 0; - i = i % 0; i = 1 << 3; i = 8 >> 2; i = 12 & 4; diff --git a/tests/cc/execute/0270-union.c b/tests/cc/execute/0270-union.c @@ -33,7 +33,6 @@ static void static void sighdl(int signo) { - return 0; } int diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore @@ -95,3 +95,5 @@ test.log 0094-bsearch 0095-abs 0096-div +0097-fops +0098-tmpfil diff --git a/tests/libc/execute/0096-div.c b/tests/libc/execute/0096-div.c @@ -14,12 +14,6 @@ done end: */ -/* -div_t div(int, int); -ldiv_t ldiv(long int, long int); -lldiv_t lldiv(long long int, long long int); -imaxdiv_t imaxdiv(intmax_t, intmax_t); -*/ static void test1(void) { diff --git a/tests/libc/execute/0097-fops.c b/tests/libc/execute/0097-fops.c @@ -0,0 +1,39 @@ +#include <assert.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +/* +output: +testing +done +end: +*/ + +int +main(void) +{ + char buff[40], *s; + FILE *fp; + + puts("testing"); + fp = fopen("__NOT_A_FILE", "w"); + assert(fp); + fputs("Hello\n", fp); + fflush(fp); + assert(ferror(fp) == 0); + fclose(fp); + assert(rename("__NOT_A_FILE", "__NOT_OTHER_FILE") == 0); + + fp = fopen("__NOT_OTHER_FILE", "r"); + assert(fp); + s = fgets(buff, sizeof(buff), fp); + assert(s != NULL); + assert(strcmp(s, "Hello\n") == 0); + fclose(fp); + + assert(remove("__NOT_OTHER_FILE") == 0); + puts("done"); + + return 0; +} diff --git a/tests/libc/execute/0098-tmpfil.c b/tests/libc/execute/0098-tmpfil.c @@ -0,0 +1,75 @@ +#include <assert.h> +#include <stdio.h> +#include <string.h> + +/* +output: +testing +test1 +test2 +done +end: +*/ + +static void +test1(void) +{ + char buf[80]; + FILE *fp1, *fp2; + + puts("test1"); + fp1 = tmpfile(); + assert(fp1); + fp2 = tmpfile(); + assert(fp2); + + fputs("This is the first\n", fp1); + fputs("This is the second\n", fp2); + fflush(fp1); + fflush(fp2); + + rewind(fp1); + rewind(fp2); + + fgets(buf, sizeof(buf), fp1); + assert(strcmp(buf, "This is the first\n") == 0); + + fgets(buf, sizeof(buf), fp2); + assert(strcmp(buf, "This is the second\n") == 0); + + assert(fclose(fp1) == 0); + assert(fclose(fp2) == 0); +} + +static void +test2(void) +{ + int i, max; + FILE *fp; + static FILE *fps[FOPEN_MAX]; + + puts("test2"); + + max = TMP_MAX - 2; + if (max > FOPEN_MAX) + max = FOPEN_MAX; + if (max > 32) + max = 32; + + for (i = 0; i < max; i++) + assert(fps[i] = tmpfile()); + + for (i = 0; i < max; i++) + assert(fclose(fps[i]) == 0); +} + +int +main(void) +{ + puts("testing"); + test1(); + test2(); + puts("done"); + + return 0; +} diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst @@ -93,3 +93,5 @@ 0094-bsearch 0095-abs 0096-div +0097-fops +0098-tmpfil