From 9b39c3f9495d63d8cdf004363bb21055c0e8865d Mon Sep 17 00:00:00 2001 From: acqn Date: Wed, 2 Nov 2022 23:58:18 +0800 Subject: [PATCH 1/3] Fixed garbage enum tag name appeared in diagnostic messages if the enum tag declaration failed. --- src/cc65/declare.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 7cc7444b6..2117b0498 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -1419,9 +1419,8 @@ static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers, } else { if (CurTok.Tok != TOK_LCURLY) { Error ("Identifier expected"); - } else { - AnonName (Ident, "enum"); } + AnonName (Ident, "enum"); } /* Remember we have an extra type decl */ D->Flags |= DS_EXTRA_TYPE; From aa5d44b2b0bc2fb8b8649f214eaa203ec4abd5e7 Mon Sep 17 00:00:00 2001 From: acqn Date: Wed, 2 Nov 2022 23:58:20 +0800 Subject: [PATCH 2/3] Fixed endlessly repeated error messages when a declaration lacks a required identifier. --- src/cc65/declare.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 2117b0498..5c55bfb5b 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -1831,7 +1831,13 @@ static void Declarator (const DeclSpec* Spec, Declaration* D, declmode_t Mode) NextToken (); } else { if (Mode == DM_NEED_IDENT) { + /* Some fix point tokens that are used for error recovery */ + static const token_t TokenList[] = { TOK_COMMA, TOK_SEMI }; + Error ("Identifier expected"); + + /* Try some smart error recovery */ + SkipTokens (TokenList, sizeof(TokenList) / sizeof(TokenList[0])); } D->Ident[0] = '\0'; } From 9253f0d6bc70d5385021a7b277999ea315645047 Mon Sep 17 00:00:00 2001 From: acqn Date: Thu, 10 Nov 2022 02:11:54 +0800 Subject: [PATCH 3/3] Added testcase for #1889. --- test/misc/Makefile | 5 +++++ test/misc/bug1889-missing-identifier.c | 9 +++++++++ test/misc/bug1889-missing-identifier.ref | 3 +++ 3 files changed, 17 insertions(+) create mode 100644 test/misc/bug1889-missing-identifier.c create mode 100644 test/misc/bug1889-missing-identifier.ref diff --git a/test/misc/Makefile b/test/misc/Makefile index e77d37b29..1a98bd2d1 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -155,6 +155,11 @@ $(WORKDIR)/goto.$1.$2.prg: goto.c $(ISEQUAL) | $(WORKDIR) $(CC65) -t sim$2 -$1 -o $$@ $$< 2>$(WORKDIR)/goto.$1.$2.out $(ISEQUAL) $(WORKDIR)/goto.$1.$2.out goto.ref +$(WORKDIR)/bug1889-missing-identifier.$1.$2.prg: bug1889-missing-identifier.c $(ISEQUAL) | $(WORKDIR) + $(if $(QUIET),echo misc/bug1889-missing-identifier.$1.$2.error.prg) + -$(CC65) -t sim$2 -$1 -o $$(@:.error.prg=.s) $$< 2> $(WORKDIR)/bug1889-missing-identifier.$1.$2.out + $(ISEQUAL) $(WORKDIR)/bug1889-missing-identifier.$1.$2.out bug1889-missing-identifier.ref + # the rest are tests that fail currently for one reason or another $(WORKDIR)/sitest.$1.$2.prg: sitest.c | $(WORKDIR) @echo "FIXME: " $$@ "currently does not compile." diff --git a/test/misc/bug1889-missing-identifier.c b/test/misc/bug1889-missing-identifier.c new file mode 100644 index 000000000..d9cf4aa52 --- /dev/null +++ b/test/misc/bug1889-missing-identifier.c @@ -0,0 +1,9 @@ +/* bug 1889 - endless errors due to failure in recovery from missing identifier */ + +int enum { a } x; +inline enum { b }; + +int main(void) +{ + return 0; +} diff --git a/test/misc/bug1889-missing-identifier.ref b/test/misc/bug1889-missing-identifier.ref new file mode 100644 index 000000000..cd3f76849 --- /dev/null +++ b/test/misc/bug1889-missing-identifier.ref @@ -0,0 +1,3 @@ +bug1889-missing-identifier.c:3: Error: Identifier expected +bug1889-missing-identifier.c:4: Error: Identifier expected +bug1889-missing-identifier.c:4: Warning: Implicit 'int' is an obsolete feature