This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[RFA] Integrated cpp -include -g fix


This is an outstanding fix + testcase for -g -include, which currently
crashes.

Would someone OK it?

Thanks,

Neil.

	* c-lex.c (orig_filename): Store original filename here.
	(init_c_lex): Don't call cpp_start_read, but set the callback
	function instead.
	(delayed_init_parse): New function.

	* toplev.c (delayed_init_parse_hook): New callback.
	(compile_file): Use it.
	* toplev.h (delayed_init_parse_hook): External declaration.

	* gcc.dg/cpp/integrated1.c: New testcase.

Index: c-lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lex.c,v
retrieving revision 1.112
diff -u -p -r1.112 c-lex.c
--- c-lex.c	2000/11/13 21:22:09	1.112
+++ c-lex.c	2000/11/15 23:03:37
@@ -61,6 +61,9 @@ extern cpp_reader  parse_in;
 FILE *finput;
 #endif
 
+/* The original file name, before changing "-" to "stdin".  */
+static const char *orig_filename;
+
 /* Private idea of the line number.  See discussion in c_lex().  */
 static int lex_lineno;
 
@@ -164,6 +167,7 @@ static void cb_enter_file	PARAMS ((cpp_r
 static void cb_leave_file	PARAMS ((cpp_reader *));
 static void cb_rename_file	PARAMS ((cpp_reader *));
 static void cb_def_pragma	PARAMS ((cpp_reader *));
+static void delayed_init_parse	PARAMS ((void));
 #endif
 
 
@@ -173,6 +177,8 @@ init_c_lex (filename)
 {
   struct c_fileinfo *toplevel;
 
+  orig_filename = filename;
+
   /* Set up filename timing.  Must happen before cpp_start_read.  */
   file_info_tree = splay_tree_new ((splay_tree_compare_fn)strcmp,
 				   0,
@@ -220,8 +226,7 @@ init_c_lex (filename)
   /* Make sure parse_in.digraphs matches flag_digraphs.  */
   CPP_OPTION (&parse_in, digraphs) = flag_digraphs;
 
-  if (! cpp_start_read (&parse_in, filename))
-    exit (FATAL_EXIT_CODE);	/* cpplib has emitted an error.  */
+  delayed_init_parse_hook = delayed_init_parse;
 
   if (filename == 0 || !strcmp (filename, "-"))
     filename = "stdin";
@@ -237,6 +242,16 @@ init_c_lex (filename)
 
   return filename;
 }
+
+#if USE_CPPLIB
+/* Called from toplev.c after debug output has been initialised.  */
+static void
+delayed_init_parse ()
+{
+  if (! cpp_start_read (&parse_in, orig_filename))
+    exit (FATAL_EXIT_CODE);	/* cpplib has emitted an error.  */
+}
+#endif
 
 struct c_fileinfo *
 get_fileinfo (name)
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.c,v
retrieving revision 1.397
diff -u -p -r1.397 toplev.c
--- toplev.c	2000/11/15 18:34:28	1.397
+++ toplev.c	2000/11/15 23:03:57
@@ -186,6 +186,9 @@ static int print_single_switch PARAMS ((
 static void print_switch_values PARAMS ((FILE *, int, int, const char *,
 				       const char *, const char *));
 
+/* Indirect pointer to yyparse.  Overridden by the C front ends.  */
+void (*delayed_init_parse_hook) PARAMS ((void));
+
 /* Length of line when printing switch values.  */
 #define MAX_LINE 75
 
@@ -2353,6 +2356,11 @@ compile_file (name)
 
   init_final (main_input_filename);
   init_branch_prob (dump_base_name);
+
+  /* Now we've initialised debug output, the C front ends can call
+     cpp_start_read.  */
+  if (delayed_init_parse_hook)
+    (*delayed_init_parse_hook) ();
 
   timevar_push (TV_PARSE);
 
Index: toplev.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.h,v
retrieving revision 1.46
diff -u -p -r1.46 toplev.h
--- toplev.h	2000/08/29 00:29:25	1.46
+++ toplev.h	2000/11/15 23:03:57
@@ -135,4 +135,8 @@ extern int sorrycount;
 
 extern const char *progname;
 
+/* The C front ends use this to call cpp_start_read after initialising
+   debug output.  */
+extern void (*delayed_init_parse_hook)	PARAMS ((void));
+
 #endif /* __GCC_TOPLEV_H */
Index: testsuite/gcc.dg/cpp/integrated1.c
===================================================================
RCS file: integrated1.c
diff -N integrated1.c
--- /dev/null	Tue May  5 13:32:27 1998
+++ integrated1.c	Wed Nov 15 15:03:57 2000
@@ -0,0 +1,11 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.  */
+
+/* { dg-do compile } */
+/* { dg-options "-g -include mi1c.h" } */
+
+/* Tests that -g -include doesn't segfault.  This used to happen
+   because cpp_start_read would be called before initialising debug
+   output for the integrated front ends.
+
+   Contributed by Neil Booth 15 Nov 2000.  */
+

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]