aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLewis Hyatt <lhyatt@gmail.com>2024-06-15 21:09:01 -0400
committerLewis Hyatt <lhyatt@gcc.gnu.org>2024-07-02 22:10:29 -0400
commit038d64f62271ddc62aa35d0a5dfd3843fdb9e6d7 (patch)
treebe39f1edbcb787fd2576d5aaf94b2996ad4bed06
parent751982484b50f3fcf54235683fb4c76dd6426d92 (diff)
downloadgcc-038d64f62271ddc62aa35d0a5dfd3843fdb9e6d7.zip
gcc-038d64f62271ddc62aa35d0a5dfd3843fdb9e6d7.tar.gz
gcc-038d64f62271ddc62aa35d0a5dfd3843fdb9e6d7.tar.bz2
preprocessor: Create the parser before handling command-line includes [PR115312]
Since r14-2893, we create a parser object in preprocess-only mode for the purpose of parsing #pragma while preprocessing. The parser object was formerly created after calling c_finish_options(), which leads to problems on platforms that don't use stdc-predef.h (such as MinGW, as reported in the PR). On such platforms, the call to c_finish_options() will process the first command-line-specified include file. If that includes a PCH, then c-ppoutput.cc will encounter a state it did not anticipate. Fix it by creating the parser prior to calling c_finish_options(). gcc/c-family/ChangeLog: PR pch/115312 * c-opts.cc (c_common_init): Call c_init_preprocess() before c_finish_options() so that a parser is available to process any includes specified on the command line. gcc/testsuite/ChangeLog: PR pch/115312 * g++.dg/pch/pr115312.C: New test. * g++.dg/pch/pr115312.Hs: New test.
-rw-r--r--gcc/c-family/c-opts.cc2
-rw-r--r--gcc/testsuite/g++.dg/pch/pr115312.C2
-rw-r--r--gcc/testsuite/g++.dg/pch/pr115312.Hs1
3 files changed, 4 insertions, 1 deletions
diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
index 33114f1..b7789b7 100644
--- a/gcc/c-family/c-opts.cc
+++ b/gcc/c-family/c-opts.cc
@@ -1296,8 +1296,8 @@ c_common_init (void)
if (flag_preprocess_only)
{
- c_finish_options ();
c_init_preprocess ();
+ c_finish_options ();
preprocess_file (parse_in);
return false;
}
diff --git a/gcc/testsuite/g++.dg/pch/pr115312.C b/gcc/testsuite/g++.dg/pch/pr115312.C
new file mode 100644
index 0000000..9074ad4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pch/pr115312.C
@@ -0,0 +1,2 @@
+/* { dg-additional-options "-include pr115312.H -save-temps" } */
+#error "suppress PCH assembly comparison, which does not work with -save-temps" /* { dg-error "." } */
diff --git a/gcc/testsuite/g++.dg/pch/pr115312.Hs b/gcc/testsuite/g++.dg/pch/pr115312.Hs
new file mode 100644
index 0000000..6e7c6bc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pch/pr115312.Hs
@@ -0,0 +1 @@
+// This space intentionally left blank.