From f48fb035405ca65f9b0a27e2cf2f7b1eb8f15631 Mon Sep 17 00:00:00 2001 From: Gorilla Sapiens Date: Fri, 2 May 2025 07:02:07 +0000 Subject: [PATCH] issue #2607, enable '\e' character escape for --standard cc65 --- doc/cc65.sgml | 10 +++++ src/cc65/scanner.c | 9 +++++ test/Makefile | 2 + test/readme.txt | 8 +++- test/standard/issue2607_cc65.c | 14 +++++++ test/standard_err/Makefile | 55 ++++++++++++++++++++++++++ test/standard_err/issue2607_not_cc65.c | 14 +++++++ 7 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 test/standard/issue2607_cc65.c create mode 100644 test/standard_err/Makefile create mode 100644 test/standard_err/issue2607_not_cc65.c diff --git a/doc/cc65.sgml b/doc/cc65.sgml index 781e460a8..6793603d5 100644 --- a/doc/cc65.sgml +++ b/doc/cc65.sgml @@ -1053,6 +1053,16 @@ This cc65 version has some extensions to the ISO C standard. unsigned char foo = 0b101; // sets it to 5 + The character escape '\e', a GCC C extension, is accepted. + In ASCII this is the escape character 0x1B, which may be + remapped in other character sets via a #pragma charmap. + It can be disabled with the option. + + + unsigned char foo = '\e'; // sets it to 0x1B or equivalent + +

diff --git a/src/cc65/scanner.c b/src/cc65/scanner.c index 879925c7c..7369d7fde 100644 --- a/src/cc65/scanner.c +++ b/src/cc65/scanner.c @@ -346,6 +346,14 @@ static int ParseChar (void) case 'b': C = '\b'; break; + case 'e': + if (IS_Get(&Standard) != STD_CC65) { + goto IllegalEscape; + } + /* we'd like to use \e here, but */ + /* not all build systems support it */ + C = '\x1B'; + break; case 'f': C = '\f'; break; @@ -411,6 +419,7 @@ static int ParseChar (void) Error ("Octal character constant out of range"); break; default: +IllegalEscape: C = CurC; Error ("Illegal escaped character: 0x%02X", CurC); break; diff --git a/test/Makefile b/test/Makefile index fbdf8c5d1..af18ddd7d 100644 --- a/test/Makefile +++ b/test/Makefile @@ -25,6 +25,7 @@ continue: @$(MAKE) -C ref all @$(MAKE) -C err all @$(MAKE) -C standard all + @$(MAKE) -C standard_err all @$(MAKE) -C misc all @$(MAKE) -C todo all @@ -35,6 +36,7 @@ mostlyclean: @$(MAKE) -C ref clean @$(MAKE) -C err clean @$(MAKE) -C standard clean + @$(MAKE) -C standard_err clean @$(MAKE) -C misc clean @$(MAKE) -C todo clean diff --git a/test/readme.txt b/test/readme.txt index d3f17148e..0aa8799b9 100644 --- a/test/readme.txt +++ b/test/readme.txt @@ -12,6 +12,8 @@ compiler is working as expected (when the tests behave as described): /val - The bulk of tests are contained here, individual tests should exit with an exit code of EXIT_SUCCESS when they pass, or EXIT_FAILURE on error. +/err - contains tests that MUST NOT compile + /standard - like the tests in /val, the tests must exit with EXIT_SUCCESS on success. Unlike the tests in /val these are not compiled for every combination of optimizer options, but instead always with -Osir and then @@ -19,6 +21,10 @@ compiler is working as expected (when the tests behave as described): to check for regressions in standard conformance of the compiler and the library. +/standard_err - like the tests in /err, these tests MUST NOT compile, and like + the tests in /standard, these are compiled -Osir and then for each + supported C-Standard. + /ref - These tests produce output that must be compared with reference output. Normally the reference output is produced by compiling the program on the host (using gcc mostly) and then running them on the host. Tests should @@ -43,8 +49,6 @@ compiler is working as expected (when the tests behave as described): only ever use this as a last resort when something can not be tested by other means. -/err - contains tests that MUST NOT compile - /todo and /misc generally contain the tests that fail because of known bugs: diff --git a/test/standard/issue2607_cc65.c b/test/standard/issue2607_cc65.c new file mode 100644 index 000000000..82ff9d1aa --- /dev/null +++ b/test/standard/issue2607_cc65.c @@ -0,0 +1,14 @@ +#include +#include + +/* this should succeed on all three standards + * yet use only \e on CC65 + */ +int main(void) { + +#if __CC65_STD__ == __CC65_STD_CC65__ + printf("\e"); +#endif + + return EXIT_SUCCESS; +} diff --git a/test/standard_err/Makefile b/test/standard_err/Makefile new file mode 100644 index 000000000..700a52eea --- /dev/null +++ b/test/standard_err/Makefile @@ -0,0 +1,55 @@ +# Makefile for the tests that MUST NOT compile + +ifneq ($(shell echo),) + CMD_EXE = 1 +endif + +ifdef CMD_EXE + S = $(subst /,\,/) + NOT = - # Hack + NULLDEV = nul: + MKDIR = mkdir $(subst /,\,$1) + RMDIR = -rmdir /s /q $(subst /,\,$1) +else + S = / + NOT = ! + NULLDEV = /dev/null + MKDIR = mkdir -p $1 + RMDIR = $(RM) -r $1 +endif + +ifdef QUIET + .SILENT: + NULLERR = 2>$(NULLDEV) +endif + +CC65 := $(if $(wildcard ../../bin/cc65*),..$S..$Sbin$Scc65,cc65) + +WORKDIR = ../../testwrk/standard_err + +OPTIONS = c89 c99 cc65 + +.PHONY: all clean + +SOURCES := $(wildcard *.c) +TESTS = $(foreach option,$(OPTIONS),$(SOURCES:%.c=$(WORKDIR)/%.$(option).6502.prg)) + +all: $(TESTS) + +$(WORKDIR): + $(call MKDIR,$(WORKDIR)) + +define PRG_template + +$(WORKDIR)/%.$1.$2.prg: %.c | $(WORKDIR) + $(if $(QUIET),echo standard_err/$$*.$1.$2.prg) + $(NOT) $(CC65) -t sim$2 $$(CC65FLAGS) -Osir --add-source --standard $1 -o $$(@:.prg=.s) $$< $(NULLERR) + +endef # PRG_template + +$(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),6502))) + +#$(foreach option,$(OPTIONS),$(eval $(call PRG_template,$(option),65c02))) + +clean: + @$(call RMDIR,$(WORKDIR)) diff --git a/test/standard_err/issue2607_not_cc65.c b/test/standard_err/issue2607_not_cc65.c new file mode 100644 index 000000000..5e56df557 --- /dev/null +++ b/test/standard_err/issue2607_not_cc65.c @@ -0,0 +1,14 @@ +#include +#include + +/* this should fail on all three standards + */ +int main(void) { + +#if __CC65_STD__ != __CC65_STD_CC65__ + printf("\e"); +#else +#error "this needs to error on CC65 to make it through validation" +#endif + return EXIT_SUCCESS; +}