Bring C++ ICE handling in line with other front ends

Zack Weinberg zack@wolery.cumb.org
Thu Jul 20 23:41:00 GMT 2000


On Thu, Jul 20, 2000 at 08:16:35PM -0700, Mark Mitchell wrote:
> >>>>> "Zack" == Zack Weinberg <zack@wolery.cumb.org> writes:
> 
>     Zack> That's fair.  What would you think of pulling that logic up
>     Zack> to toplev.c so everyone got it?  I'm after consistency here.
> 
> Yes, that idea I like.

I'll send a separate patch for that, tomorrow or so.

>     Zack> Okay.  I'll have to bootstrap again, then I'll post a
>     Zack> revised patch.
> 
> Great, thanks.  Assuming it all works OK, check it in.

It did.  Here is the patch I have committed.

zw

	* cp-tree.h: Use __FUNCTION__ not __PRETTY_FUNCTION__.
	Define my_friendly_assert and my_friendly_abort as macros
	which may call friendly_abort.  Prototype friendly abort, not
	my_friendly_abort or my_friendly_assert.
	* decl.c (signal_catch): Report the signal caught in the error
	message.  Call fatal directly.
	* typeck2.c (ack, my_friendly_assert): Delete.
	(my_friendly_abort): Rename to friendly_abort.  Expect file,
	line, and function parameters.  Report the abort code, then
	call fancy_abort.  Do not mask an abort if errors have
	already occurred.

	* g++.old-deja/g++.brendan/crash16.C,
	g++.old-deja/g++.brendan/parse3.C,
	g++.old-deja/g++.brendan/redecl1.C,
	g++.old-deja/g++.ns/template13.C,
	g++.old-deja/g++.other/decl4.C,
	g++.old-deja/g++.pt/spec14.C: Mark as crash test, expected to fail.

===================================================================
Index: cp/cp-tree.h
--- cp/cp-tree.h	2000/07/16 21:04:16	1.499
+++ cp/cp-tree.h	2000/07/21 06:34:50
@@ -161,8 +161,8 @@ Boston, MA 02111-1307, USA.  */
 ({  const tree __t = NODE;					\
     enum tree_code __c = TREE_CODE(__t);			\
     if (__c != VAR_DECL && __c != FUNCTION_DECL)		\
-      tree_check_failed (__t, VAR_DECL, __FILE__,		\
-			 __LINE__, __PRETTY_FUNCTION__);	\
+      tree_check_failed (__t, VAR_DECL, __FILE__, __LINE__,	\
+			 __FUNCTION__);				\
     __t; })
 
 #define VAR_FUNCTION_OR_PARM_DECL_CHECK(NODE)			\
@@ -171,8 +171,8 @@ Boston, MA 02111-1307, USA.  */
     if (__c != VAR_DECL 					\
 	&& __c != FUNCTION_DECL 				\
         && __c != PARM_DECL)					\
-      tree_check_failed (__t, VAR_DECL, __FILE__,		\
-			 __LINE__, __PRETTY_FUNCTION__);	\
+      tree_check_failed (__t, VAR_DECL, __FILE__, __LINE__,	\
+			 __FUNCTION__);				\
     __t; })
 
 #define VAR_TEMPL_TYPE_OR_FUNCTION_DECL_CHECK(NODE)		\
@@ -182,16 +182,16 @@ Boston, MA 02111-1307, USA.  */
 	&& __c != FUNCTION_DECL					\
 	&& __c != TYPE_DECL					\
 	&& __c != TEMPLATE_DECL)				\
-      tree_check_failed (__t, VAR_DECL, __FILE__,		\
-			 __LINE__, __PRETTY_FUNCTION__);	\
+      tree_check_failed (__t, VAR_DECL, __FILE__, __LINE__,	\
+			 __FUNCTION__);				\
     __t; })
 
 #define RECORD_OR_UNION_TYPE_CHECK(NODE)			\
 ({  const tree __t = NODE;					\
     enum tree_code __c = TREE_CODE(__t);			\
     if (__c != RECORD_TYPE && __c != UNION_TYPE)		\
-      tree_check_failed (__t, RECORD_TYPE, __FILE__,		\
-			 __LINE__, __PRETTY_FUNCTION__);	\
+      tree_check_failed (__t, RECORD_TYPE, __FILE__, __LINE__,	\
+			 __FUNCTION__);				\
     __t; })
 
 #else /* not ENABLE_TREE_CHECKING, or not gcc */
@@ -4629,9 +4629,15 @@ extern tree binfo_or_else			PARAMS ((tre
 extern void readonly_error			PARAMS ((tree, const char *, int));
 extern int abstract_virtuals_error		PARAMS ((tree, tree));
 extern void incomplete_type_error		PARAMS ((tree, tree));
-extern void my_friendly_abort			PARAMS ((int))
+extern void friendly_abort			PARAMS ((int, const char *,
+							 int, const char *))
   ATTRIBUTE_NORETURN;
-extern void my_friendly_assert			PARAMS ((int, int));
+
+#define my_friendly_abort(N) \
+  friendly_abort (N, __FILE__, __LINE__, __FUNCTION__)
+#define my_friendly_assert(EXP, N) \
+ (((EXP) == 0) ? (friendly_abort (N, __FILE__, __LINE__, __FUNCTION__), 0) : 0)
+
 extern tree store_init_value			PARAMS ((tree, tree));
 extern tree digest_init				PARAMS ((tree, tree, tree *));
 extern tree build_scoped_ref			PARAMS ((tree, tree));
===================================================================
Index: cp/decl.c
--- cp/decl.c	2000/07/17 21:35:46	1.656
+++ cp/decl.c	2000/07/21 06:34:54
@@ -6105,7 +6105,7 @@ end_only_namespace_names ()
 
 static void
 signal_catch (sig)
-     int sig ATTRIBUTE_UNUSED;
+     int sig;
 {
   signal (SIGSEGV, SIG_DFL);
 #ifdef SIGIOT
@@ -6120,7 +6120,10 @@ signal_catch (sig)
 #ifdef SIGBUS
   signal (SIGBUS, SIG_DFL);
 #endif
-  my_friendly_abort (0);
+
+  fatal ("Internal error: %s\n\
+Please submit a full bug report.\n\
+See %s for instructions.", strsignal (sig), GCCBUGURL);
 }
 
 /* Push the declarations of builtin types into the namespace.
===================================================================
Index: cp/typeck2.c
--- cp/typeck2.c	2000/07/10 03:47:36	1.85
+++ cp/typeck2.c	2000/07/21 06:34:54
@@ -40,7 +40,6 @@ Boston, MA 02111-1307, USA.  */
 #include "output.h"
 
 static tree process_init_constructor PARAMS ((tree, tree, tree *));
-static void ack PARAMS ((const char *, ...)) ATTRIBUTE_PRINTF_1;
 
 /* Print an error message stemming from an attempt to use
    BASETYPE as a base class for TYPE.  */
@@ -246,102 +245,23 @@ retry:
     cp_error_at ("incomplete `%D' defined here", value);
 }
 
-/* Like error(), but don't call report_error_function().  */
-
-static void
-ack VPARAMS ((const char *msg, ...))
-{
-#ifndef ANSI_PROTOTYPES
-  const char *msg;
-#endif
-  va_list ap;
-  
-  VA_START (ap, msg);
-
-#ifndef ANSI_PROTOTYPES
-  msg = va_arg (ap, const char *);
-#endif
-  
-  if (input_filename)
-    fprintf (stderr, "%s:%d: ", input_filename, lineno);
-  else
-    fprintf (stderr, "%s: ", progname);
-
-  vfprintf (stderr, msg, ap);
-  va_end (ap);
-  
-  fprintf (stderr, "\n");
-}
-  
-/* There are times when the compiler can get very confused, confused
-   to the point of giving up by aborting, simply because of previous
-   input errors.  It is much better to have the user go back and
-   correct those errors first, and see if it makes us happier, than it
-   is to abort on him.  This is because when one has a 10,000 line
-   program, and the compiler comes back with ``core dump'', the user
-   is left not knowing even where to begin to fix things and no place
-   to even try and work around things.
-
-   The parameter is to uniquely identify the problem to the user, so
-   that they can say, I am having problem 59, and know that fix 7 will
-   probably solve their problem.  Or, we can document what problem
-   59 is, so they can understand how to work around it, should they
-   ever run into it.
-
-   We used to tell people to "fix the above error[s] and try recompiling
-   the program" via a call to fatal, but that message tended to look
-   silly.  So instead, we just do the equivalent of a call to fatal in the
-   same situation (call exit).
-
-   We used to assign sequential numbers for the aborts; now we use an
-   encoding of the date the abort was added, since that has more meaning
-   when we only see the error message.  */
-
-static int abortcount = 0;
-
+/* This is a wrapper around fancy_abort, as used in the back end and
+   other front ends.  It will also report the magic number assigned to
+   this particular abort.  That is for backward compatibility with the
+   old C++ abort handler, which would just report the magic number.  */
 void
-my_friendly_abort (i)
-     int i;
+friendly_abort (where, file, line, func)
+     int where;
+     const char *file;
+     int line;
+     const char *func;
 {
-  /* if the previous error came through here, i.e. report_error_function
-     ended up calling us again, don't just exit; we want a diagnostic of
-     some kind.  */
-  if (abortcount == 1)
-    current_function_decl = NULL_TREE;
-  else if (errorcount > 0 || sorrycount > 0)
-    {
-      if (abortcount > 1)
-	{
-	  if (i == 0)
-	    ack ("Internal compiler error.");
-	  else
-	    ack ("Internal compiler error %d.", i);
-	  ack ("Please submit a full bug report.");
-	  ack ("See %s for instructions.", GCCBUGURL);
-	}
-      else
-	error ("confused by earlier errors, bailing out");
-      
-      exit (34);
-    }
-  ++abortcount;
-
-  if (i == 0)
-    error ("Internal compiler error.");
-  else
-    error ("Internal compiler error %d.", i);
+  if (where > 0)
+    error ("Internal error #%d.", where);
 
-  error ("Please submit a full bug report.");
-  fatal ("See %s for instructions.", GCCBUGURL);
+  fancy_abort (file, line, func);
 }
 
-void
-my_friendly_assert (cond, where)
-     int cond, where;
-{
-  if (cond == 0)
-    my_friendly_abort (where);
-}
 
 /* Perform appropriate conversions on the initial value of a variable,
    store it in the declaration DECL,
===================================================================
Index: testsuite/g++.old-deja/g++.brendan/crash16.C
--- testsuite/g++.old-deja/g++.brendan/crash16.C	1998/12/16 21:23:26	1.2
+++ testsuite/g++.old-deja/g++.brendan/crash16.C	2000/07/21 06:34:54
@@ -1,5 +1,6 @@
 // Build don't link: 
 // GROUPS passed old-abort
+// crash test - XFAIL *-*-*
 class Graph {
 public:
       unsigned         char N;
===================================================================
Index: testsuite/g++.old-deja/g++.brendan/parse3.C
--- testsuite/g++.old-deja/g++.brendan/parse3.C	1998/12/16 21:26:41	1.3
+++ testsuite/g++.old-deja/g++.brendan/parse3.C	2000/07/21 06:34:54
@@ -1,4 +1,5 @@
 // Build don't link: 
+// crash test - XFAIL *-*-*
 
 // these are marked as expected errors because they evidence an
 // ambiguity in the grammar between expressions and declarations.
===================================================================
Index: testsuite/g++.old-deja/g++.brendan/redecl1.C
--- testsuite/g++.old-deja/g++.brendan/redecl1.C	1998/12/16 21:26:57	1.2
+++ testsuite/g++.old-deja/g++.brendan/redecl1.C	2000/07/21 06:34:54
@@ -1,5 +1,6 @@
 // Build don't link: 
 // GROUPS passed redeclaration
-inline int min(int x, int y) {return x < y ? x : y;}		/* 235 */// ERROR - .*
+// crash test - XFAIL *-*-*
+inline int min(int x, int y) {return x < y ? x : y;}	/* 235 */// ERROR - .*
 int min(int a, int b);
 inline int min(int a, int b) {return (a < b)?a:b;}// ERROR - .*
===================================================================
Index: testsuite/g++.old-deja/g++.ns/template13.C
--- testsuite/g++.old-deja/g++.ns/template13.C	1999/08/30 05:36:00	1.4
+++ testsuite/g++.old-deja/g++.ns/template13.C	2000/07/21 06:34:54
@@ -1,5 +1,6 @@
 // Build don't link:
 // Templates defined outside must be declared inside
+// crash test - XFAIL *-*-*
 namespace bar
 {
   template<class T>
===================================================================
Index: testsuite/g++.old-deja/g++.other/decl4.C
--- testsuite/g++.old-deja/g++.other/decl4.C	2000/06/11 03:38:05	1.4
+++ testsuite/g++.old-deja/g++.other/decl4.C	2000/07/21 06:34:54
@@ -1,4 +1,5 @@
 // Build don't link:
+// crash test - XFAIL *-*-*
 
 // Reported by Harri Porten <porten@tu-harburg.de>
 // Simplified for testsuite by Alexandre Oliva
===================================================================
Index: testsuite/g++.old-deja/g++.pt/spec14.C
--- testsuite/g++.old-deja/g++.pt/spec14.C	1998/12/16 21:59:54	1.2
+++ testsuite/g++.old-deja/g++.pt/spec14.C	2000/07/21 06:34:54
@@ -1,3 +1,4 @@
+// crash test - XFAIL *-*-*
 class X
 {
 public:


More information about the Gcc-patches mailing list