scc

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

commit c4b7c0458ffee84c043739645afe0aedffb906ed
parent 2b37e1b627adcc3ec5db9ec47cd91669d8bfb8a5
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Wed, 17 Jun 2026 14:44:08 +0200

Merge remote-tracking branch 'origin/master'

Diffstat:
MREADME | 5+++--
Minclude/scc/bits/scc/sys-musl.h | 1+
Minclude/scc/bits/scc/sys-scc.h | 1+
Msrc/cmd/scc-cc/cc1/cc1.h | 4++--
Msrc/cmd/scc-cc/cc1/decl.c | 8++++++--
Msrc/cmd/scc-cc/posix/cc.c | 4++--
Msrc/libc/Makefile | 2+-
Msrc/libc/rules.mk | 10++++++++--
Atests/cc/error/0042-struct-enum.c | 11+++++++++++
Mtests/cc/error/scc-tests.lst | 1+
Atests/cc/execute/0275-struct.c | 12++++++++++++
Mtests/cc/execute/scc-tests.lst | 1+
12 files changed, 49 insertions(+), 11 deletions(-)

diff --git a/README b/README @@ -208,6 +208,8 @@ file `include/bits/scc/sys.h` and it included basically 5 elements: - ASBIN: macro with the name of the assembler binary. + - QBEBIN: macro with the name of the qbe binary. + - sysincludes: It is a list of diretories used to locate the system headers @@ -244,8 +246,7 @@ Runtime dependencies ==================== Some configurations of scc require having the QBE [1] executable in the PATH, -whose version must support common storage which was incorporated to it after -the commit 8ded7a5, but it is not part of a stable release of QBE yet. +whose version must support common storage which was incorporated in QBE 1.3. [1] https://c9x.me/compile/ diff --git a/include/scc/bits/scc/sys-musl.h b/include/scc/bits/scc/sys-musl.h @@ -1,5 +1,6 @@ #define LDBIN "ld" #define ASBIN "as" +#define QBEBIN "qbe" /* configure below your system linker command line */ #define GCCLIBPATH "/usr/lib/gcc/x86_64-unknown-linux-gnu/10.2/" diff --git a/include/scc/bits/scc/sys-scc.h b/include/scc/bits/scc/sys-scc.h @@ -1,5 +1,6 @@ #define LDBIN "ld" #define ASBIN "as" +#define QBEBIN "qbe" /* configure below your standard sys include paths */ char *sysincludes[] = { diff --git a/src/cmd/scc-cc/cc1/cc1.h b/src/cmd/scc-cc/cc1/cc1.h @@ -24,9 +24,9 @@ enum { enum typeprops { TDEFINED = 1 << 0, /* type defined */ TSIGNED = 1 << 1, /* signedness of the type */ - TINTEGER = 1 << 2, /* the type is INT of enum */ + TINTEGER = 1 << 2, /* the type is INT or ENUM */ TARITH = 1 << 3, /* the type is INT, ENUM or FLOAT */ - TAGGREG = 1 << 4, /* the type is struct or union */ + TAGGREG = 1 << 4, /* the type is STRUCT or UNION */ TK_R = 1 << 5, /* this is a K&R-function */ TELLIPSIS= 1 << 6, /* this function has an ellipsis par */ TFUNDEF = 1 << 7, /* function definition */ diff --git a/src/cmd/scc-cc/cc1/decl.c b/src/cmd/scc-cc/cc1/decl.c @@ -755,7 +755,6 @@ specifier(int *sclass, int *qualifier) if (size || sign) errorp("invalid type specification"); tp = (*dcl)(); - goto return_type; } else { next(); } @@ -833,8 +832,11 @@ structdcl(void) sym = newtag(); tp = sym->type; - if (!accept('{')) + if (!accept('{')) { + if (sym->name == NULL) + unexpected(); return tp; + } ns = namespace; namespace = tp->ns; @@ -869,6 +871,8 @@ enumdcl(void) namespace = NS_IDEN; if (!accept('{')) { + if (tagsym->name == NULL) + unexpected(); namespace = ns; return tp; } diff --git a/src/cmd/scc-cc/posix/cc.c b/src/cmd/scc-cc/posix/cc.c @@ -53,7 +53,7 @@ static struct tool { [TEEIR] = {.bin = "tee"}, [CC2] = {.bin = "cc2"}, [TEEQBE] = {.bin = "tee"}, - [QBE] = {.bin = "qbe"}, + [QBE] = {.bin = QBEBIN}, [TEEAS] = {.bin = "tee"}, [AS] = {.bin = ASBIN}, [LD] = {.bin = LDBIN}, @@ -242,7 +242,7 @@ settool(int tool, char *infile, int nexttool) die("scc-cc: target tool path is too long"); break; case QBE: - strcpy(t->cmd, "qbe"); + strcpy(t->cmd, QBEBIN); if (!strcmp(arch, "amd64") && !strcmp(abi, "sysv")) fmt = "amd64_sysv"; diff --git a/src/libc/Makefile b/src/libc/Makefile @@ -18,7 +18,7 @@ include rules.mk include objs/$(ARCH)-$(SYS).mk NODEP = 1 -TARGET = $(LIBC) $(BINDIR)/gcc-scc +TARGET = $(LIBC) all: $(DIRS) +@$(MAKE) $(TARGET) diff --git a/src/libc/rules.mk b/src/libc/rules.mk @@ -7,6 +7,12 @@ SYSERRNO = $(INCDIR)/bits/$(SYS)/sys/errno.h LIBC = $(LIBCDIR)/libc.a CRT = $(LIBCDIR)/crt.o +CPPINCLUDES =\ + -I$(INCDIR)\ + -I$(INCDIR)/bits/$(SYS)\ + -I$(INCDIR)/bits/$(ARCH)\ + -I$(INCDIR)/bits/$(SYS)/$(ARCH)\ + # Rules .SUFFIXES: .$O @@ -15,7 +21,7 @@ _sys_errlist.c: $(SYSERRNO) ../../mkerrstr $(SYSERRNO) _sys_errlist.$O: _sys_errlist.c - $(CC) $(CFLAGS) -c -o $@ _sys_errlist.c + $(CC) $(CFLAGS) $(CPPINCLUDES) -c -o $@ _sys_errlist.c $(CRT): crt.$O cp crt.$O $@ @@ -26,7 +32,7 @@ clean-libc: FORCE rm -f *.5? *.6? *.7? *.8? *.z *.q .c.$O: - $(CC) $(CFLAGS) -o $@ -c $< + $(CC) $(CFLAGS) $(CPPINCLUDES) -o $@ -c $< .s.$O: $(AS) $(PROJ_ASFLAGS) $< -o $@ diff --git a/tests/cc/error/0042-struct-enum.c b/tests/cc/error/0042-struct-enum.c @@ -0,0 +1,11 @@ +/* +PATTERN: +0042-struct-enum.c:9: error: unexpected 'const' +0042-struct-enum.c:10: error: unexpected 'const' +0042-struct-enum.c:11: error: unexpected 'const' +. +*/ + +struct const tag1 { int v; }; +union const tag2 { int v; }; +enum const tag3 { VALUE }; diff --git a/tests/cc/error/scc-tests.lst b/tests/cc/error/scc-tests.lst @@ -39,3 +39,4 @@ 0039-struct.c 0040-vararg.c 0041-iconst.c +0042-struct-enum.c [TODO] diff --git a/tests/cc/execute/0275-struct.c b/tests/cc/execute/0275-struct.c @@ -0,0 +1,12 @@ +struct S { int a; int b; }; +struct S const s = {1, 2}; + +int +main() +{ + if(s.a != 1) + return 1; + if(s.b != 2) + return 2; + return 0; +} diff --git a/tests/cc/execute/scc-tests.lst b/tests/cc/execute/scc-tests.lst @@ -265,3 +265,4 @@ 0272-div 0273-cpp 0274-loop +0275-struct