commit 821b36493976e2c758a36ca35af741c490dc74d4
parent b08abffa5c4d301dbb5b568fa3543cade0671afd
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Mon, 13 Feb 2023 14:45:01 +0100
cc1: Finish when no more input available
It does not make sense to continue parsing when
there is no more input available.
Diffstat:
4 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/src/cmd/cc/cc1/lex.c b/src/cmd/cc/cc1/lex.c
@@ -942,9 +942,6 @@ discard(void)
extern jmp_buf recover;
int c;
- if (!input)
- return;
-
for (c = yytoken; ; c = *input->p++) {
switch (safe) {
case END_COMP:
@@ -964,8 +961,8 @@ discard(void)
goto jump;
break;
}
- if (c == '\0' && !moreinput())
- exit(1);
+ if ((c == '\0' || c == EOFTOK) && !moreinput())
+ exit(EXIT_FAILURE);
}
jump:
input->begin = input->p;
diff --git a/tests/cc/error/0029-eof.c b/tests/cc/error/0029-eof.c
@@ -1,9 +1,6 @@
/*
PATTERN:
-0029-eof.c:11: error: unexpected '<EOF>'
-0029-eof.c:11: warning: type defaults to 'int' in declaration
-0029-eof.c:11: error: expected ')' before '<EOF>'
-0029-eof.c:11: error: expected ';' before '<EOF>'
+0029-eof.c:8: error: unexpected '<EOF>'
.
*/
diff --git a/tests/cc/error/0034-eof.c b/tests/cc/error/0034-eof.c
@@ -0,0 +1,10 @@
+/*
+PATTERN:
+0034-eof.c:10: error: unexpected '<EOF>'
+.
+*/
+int
+main()
+{
+ int *p;
+ p = 3;
diff --git a/tests/cc/error/scc-tests.lst b/tests/cc/error/scc-tests.lst
@@ -31,3 +31,4 @@
0031-krtypes.c
0032-krtypes.c
0033-character.c
+0034-eof.c