This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH don't segfault in cc1 if main file mssing [fixes preprocessor/12545]
- From: Per Bothner <per at bothner dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 11 Oct 2003 00:50:07 -0700
- Subject: PATCH don't segfault in cc1 if main file mssing [fixes preprocessor/12545]
The attached patch should fix PR preprocessor/12545,
where cc1 segfails if asked to compile a missing file.
(This is not a critical bug, since gcc will normally
complain first if the main file is missing.)
I've run the testsuite, and there are fewer unexpected
failures than last time I ran the testsite - but there
are some new ones in a additionto some that have gone
away. Sigh. I'll try again with a clean tree to
double-check that there are no regressions before
checking in.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
2003-10-11 Per Bothner <pbothner@apple.com>
* c-opts.c (finish_options): Change to returns boolean - false iff
the call to cpp_find_main_file fails.
(c_common_init): Skip preprocess_file if finish_options failed.
(c_common_parse_file): Break if finish_options failed.
Index: c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.91
diff -u -p -r1.91 c-opts.c
--- c-opts.c 2 Oct 2003 07:25:02 -0000 1.91
+++ c-opts.c 11 Oct 2003 07:31:29 -0000
@@ -108,7 +108,7 @@ static void sanitize_cpp_opts (void);
static void add_prefixed_path (const char *, size_t);
static void push_command_line_include (void);
static void cb_file_change (cpp_reader *, const struct line_map *);
-static void finish_options (const char *);
+static bool finish_options (const char *);
#ifndef STDC_0_IN_SYSTEM_HEADERS
#define STDC_0_IN_SYSTEM_HEADERS 0
@@ -1183,8 +1183,8 @@ c_common_init (void)
if (flag_preprocess_only)
{
- finish_options (in_fnames[0]);
- preprocess_file (parse_in);
+ if (finish_options (in_fnames[0]))
+ preprocess_file (parse_in);
return false;
}
@@ -1220,7 +1220,8 @@ c_common_parse_file (int set_yydebug ATT
cpp_undef_all (parse_in);
}
- finish_options(in_fnames[file_index]);
+ if (! finish_options(in_fnames[file_index]))
+ break;
if (file_index == 0)
pch_init();
c_parse_file ();
@@ -1387,8 +1388,8 @@ add_prefixed_path (const char *suffix, s
/* Handle -D, -U, -A, -imacros, and the first -include.
TIF is the input file to which we will return after processing all
- the includes. */
-static void
+ the includes. Returns true on success. */
+static bool
finish_options (const char *tif)
{
if (!cpp_opts->preprocessed)
@@ -1441,8 +1442,10 @@ finish_options (const char *tif)
include_cursor = 0;
this_input_filename = tif;
- cpp_find_main_file (parse_in, this_input_filename);
+ if (! cpp_find_main_file (parse_in, this_input_filename))
+ return false;
push_command_line_include ();
+ return true;
}
/* Give CPP the next file given by -include, if any. */