http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52306
--- Comment #14 from Thorsten Glaser <tg at mirbsd dot org> 2013-01-29 23:29:54 UTC --- just don’t hit me… I’m trying this now, until someone fixes this PR: # DP: retry a known ICE with -O1 then -O0 in case it gets better --- a/src/gcc/diagnostic.c +++ b/src/gcc/diagnostic.c @@ -242,6 +242,12 @@ diagnostic_action_after_output (diagnost "See %s for instructions.\n", bug_report_url); exit (ICE_EXIT_CODE); + case DK_TGV: + fnotice (stderr, "Retrying with lowered optimisation,\n" + "this is a known bug, do not worry. If it'll\n" + "still fail, just fail the package build.\n"); + exit (TGV_EXIT_CODE); + case DK_FATAL: if (context->abort_on_error) real_abort (); @@ -426,7 +432,7 @@ diagnostic_report_diagnostic (diagnostic /* If we're reporting an ICE in the middle of some other error, try to flush out the previous error, then let this one through. Don't do this more than once. */ - if (diagnostic->kind == DK_ICE && context->lock == 1) + if ((diagnostic->kind == DK_ICE || diagnostic->kind == DK_TGV) && context->lock == 1) pp_flush (context->printer); else error_recursion (context); @@ -494,7 +500,7 @@ diagnostic_report_diagnostic (diagnostic context->lock++; - if (diagnostic->kind == DK_ICE) + if (diagnostic->kind == DK_ICE || diagnostic->kind == DK_TGV) { #ifndef ENABLE_CHECKING /* When not checking, ICEs are converted to fatal errors when an @@ -507,7 +513,7 @@ diagnostic_report_diagnostic (diagnostic expanded_location s = expand_location (diagnostic->location); fnotice (stderr, "%s:%d: confused by earlier errors, bailing out\n", s.file, s.line); - exit (ICE_EXIT_CODE); + exit (diagnostic->kind == DK_TGV ? TGV_EXIT_CODE : ICE_EXIT_CODE); } #endif if (context->internal_error) @@ -902,3 +908,17 @@ real_abort (void) { abort (); } + +void +tgv_abort (const char *gmsgid, ...) +{ + diagnostic_info diagnostic; + va_list ap; + + va_start (ap, gmsgid); + diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_TGV); + report_diagnostic (&diagnostic); + va_end (ap); + + gcc_unreachable (); +} --- a/src/gcc/diagnostic.def +++ b/src/gcc/diagnostic.def @@ -43,3 +43,4 @@ prefix does not matter. */ DEFINE_DIAGNOSTIC_KIND (DK_PEDWARN, "pedwarn: ") DEFINE_DIAGNOSTIC_KIND (DK_PERMERROR, "permerror: ") +DEFINE_DIAGNOSTIC_KIND (DK_TGV, "internal compiler error: ") --- a/src/gcc/system.h +++ b/src/gcc/system.h @@ -235,6 +235,7 @@ extern int errno; #endif #define ICE_EXIT_CODE 4 +#define TGV_EXIT_CODE 23 #ifdef HAVE_UNISTD_H # include <unistd.h> @@ -642,6 +643,15 @@ extern void fancy_abort (const char *, i #define gcc_assert(EXPR) ((void)(0 && (EXPR))) #endif +extern void tgv_abort (const char *, ...) ATTRIBUTE_NORETURN; +#if ENABLE_ASSERT_CHECKING +#define gcc_assert_and_retry_with_lowered_optimisation_level(EXPR) \ + ((void)(!(EXPR) ? tgv_abort ("in %s, at %s:%d", __FUNCTION__, trim_filename (__FILE__), __LINE__), 0 : 0)) +#else +#define gcc_assert_and_retry_with_lowered_optimisation_level(EXPR) \ + gcc_assert (EXPR) +#endif + #ifdef ENABLE_CHECKING #define gcc_checking_assert(EXPR) gcc_assert (EXPR) #else --- a/src/gcc/gcc.c +++ b/src/gcc/gcc.c @@ -253,6 +253,7 @@ static const char *convert_filename (con #if !(defined (__MSDOS__) || defined (OS2) || defined (VMS)) static void retry_ice (const char *prog, const char **argv); #endif +static const char **tgv_argv(const char **); static const char *getenv_spec_function (int, const char **); static const char *if_exists_spec_function (int, const char **); @@ -2464,6 +2465,7 @@ execute (void) { int i; int n_commands; /* # of command. */ + int retry_tgv = 0; char *string; struct pex_obj *pex; struct command @@ -2529,7 +2531,8 @@ execute (void) /* If -v, print what we are about to do, and maybe query. */ - if (verbose_flag) + do { + if (verbose_flag || retry_tgv) { /* For help listings, put a blank line between sub-processes. */ if (print_help_list) @@ -2659,13 +2662,12 @@ execute (void) pfatal_with_name (errmsg); } } - - if (i && string != commands[i].prog) - free (CONST_CAST (char *, string)); } execution_count++; + retry_tgv &= ~0x80; + /* Wait for all the subprocesses to finish. */ { @@ -2717,6 +2719,26 @@ execute (void) /* For ICEs in cc1, cc1obj, cc1plus see if it is reproducible or not. */ const char *p; + if (WEXITSTATUS (status) == TGV_EXIT_CODE + && i == 0 + && (p = strrchr (commands[0].argv[0], DIR_SEPARATOR)) + && ! strncmp (p + 1, "cc1", 3)) { + if (retry_tgv == 0) { + commands[0].argv = tgv_argv(commands[0].argv); + retry_tgv = 0x81; + goto foo_tgv; + } + if (retry_tgv == 1) { + size_t qqq = 0; + + while (commands[0].argv[qqq]) + ++qqq; + commands[0].argv[--qqq] = "-O0"; + retry_tgv = 0x82; + goto foo_tgv; + } + retry_tgv = 3; + } if (WEXITSTATUS (status) == ICE_EXIT_CODE && i == 0 && (p = strrchr (commands[0].argv[0], DIR_SEPARATOR)) @@ -2725,6 +2747,7 @@ execute (void) #endif if (WEXITSTATUS (status) > greatest_status) greatest_status = WEXITSTATUS (status); + foo_tgv: ret_code = -1; } @@ -2779,12 +2802,12 @@ execute (void) } } } - - if (commands[0].argv[0] != commands[0].prog) - free (CONST_CAST (char *, commands[0].argv[0])); - + if (!(retry_tgv & 0x80)) return ret_code; + retry_tgv &= ~0x80; } + } while (retry_tgv < 3); + return TGV_EXIT_CODE; } /* Find all the switches given to us @@ -8587,3 +8610,22 @@ pass_through_libs_spec_func (int argc, c } return prepended; } + +static const char ** +tgv_argv(const char **oargv) +{ + size_t qqq = 0; + const char **rv; + + while (oargv[qqq]) + ++qqq; + rv = (const char **)xmalloc((qqq + 2) * sizeof(const char *)); + qqq = 0; + while (oargv[qqq]) { + rv[qqq] = oargv[qqq]; + ++qqq; + } + rv[qqq++] = "-O1"; + rv[qqq] = NULL; + return (rv); +} --- a/src/gcc/cselib.c +++ b/src/gcc/cselib.c @@ -2155,7 +2155,7 @@ cselib_record_set (rtx dest, cselib_val else { /* The register should have been invalidated. */ - gcc_assert (REG_VALUES (dreg)->elt == 0); + gcc_assert_and_retry_with_lowered_optimisation_level (REG_VALUES (dreg)->elt == 0); REG_VALUES (dreg)->elt = src_elt; }