ref: 493d1fe087d5b30f9a74b6e51697e10ea6fc9ad8
parent: 75e4d370040c4a766e97c3663d92aac9ee0dce1e
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Jun 22 05:07:00 EDT 2016
[cc1] Fix comments across several files If a comment finishes before of the end of its file then we have to continue from the previous file, and give a message error when we arrive to the end of the base file.
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -127,7 +127,7 @@
die("error: input file '%s' too long", input->fname);
}
-static char
+static int
readchar(void)
{
int c;
@@ -134,6 +134,8 @@
FILE *fp;
repeat:
+ if (eof)
+ return 0;
fp = input->fp;
switch (c = getc(fp)) {
@@ -157,21 +159,24 @@
}
static void
-comment(char type)
+comment(int type)
{
- if (type == '*') {
- while (!eof) {
- while (readchar() != '*' && !eof)
- /* nothing */;
- if (readchar() == '/')
- break;
- }
- } else {
- while (readchar() != '\n' && !eof)
- /* nothing */;
+ int c;
+
+ c = -1;
+repeat:
+ do {
+ if (!c)
+ delinput();
+ } while (!eof && (c = readchar()) != type);
+
+ if (eof) {
+ errorp("unterminated comment");
+ return;
}
- if (eof)
- error("unterminated comment");
+
+ if (type == '*' && (c = readchar()) != '/')
+ goto repeat;
}
static int
@@ -201,6 +206,8 @@
peekc = c;
c = '/';
} else {
+ if (c == '/')
+ c = '\n';
comment(c);
c = ' ';
}
--- /dev/null
+++ b/cc1/tests/test063.c
@@ -1,0 +1,12 @@
+/* See LICENSE file for copyright and license details. */
+
+/*
+name: TEST063
+description: Test a comment that goes beyond of the end of an included file
+error:
+test063.c:12: error: unterminated comment
+test063.c:12: error: #endif expected
+output:
+*/
+
+#include "test063.h"
--- /dev/null
+++ b/cc1/tests/test063.h
@@ -1,0 +1,9 @@
+
+#ifndef TEST_H_
+#define TEST_H_
+
+/*
+ This is an unterminated comment.
+
+
+#endif