From 4094757e4be196c5a0f059e96ad149263c60555e Mon Sep 17 00:00:00 2001
From: Richard Biener <rguenther@suse.de>
Date: Tue, 25 Feb 2014 08:57:42 +0000
Subject: [PATCH] re PR lto/60319 (wrong code (that hangs) by LTO at -Os and
 above on x86_64-linux-gnu)

2014-02-25  Richard Biener  <rguenther@suse.de>

	PR lto/60319
	* lto-opts.c (lto_write_options): Output non-explicit conservative
	-fwrapv, -fno-trapv and -fno-strict-overflow.
	* lto-wrapper.c (merge_and_complain): Handle merging those options.
	(run_gcc): And pass them through.

From-SVN: r208112
---
 gcc/ChangeLog     |  8 ++++++++
 gcc/lto-opts.c    | 12 ++++++++++++
 gcc/lto-wrapper.c | 21 ++++++++++++++++++++-
 3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 385179b9c76..a7efc6528a6 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2014-02-25  Richard Biener  <rguenther@suse.de>
+
+	PR lto/60319
+	* lto-opts.c (lto_write_options): Output non-explicit conservative
+	-fwrapv, -fno-trapv and -fno-strict-overflow.
+	* lto-wrapper.c (merge_and_complain): Handle merging those options.
+	(run_gcc): And pass them through.
+
 2014-02-25  Andrey Belevantsev  <abel@ispras.ru>
 	
 	* sel-sched.c (calculate_new_fences): New parameter ptime.
diff --git a/gcc/lto-opts.c b/gcc/lto-opts.c
index 3f6757287d4..06796d62a3e 100644
--- a/gcc/lto-opts.c
+++ b/gcc/lto-opts.c
@@ -117,6 +117,18 @@ lto_write_options (void)
       default:
 	gcc_unreachable ();
       }
+  /* We need to merge -f[no-]strict-overflow, -f[no-]wrapv and -f[no-]trapv
+     conservatively, so stream out their defaults.  */
+  if (!global_options_set.x_flag_wrapv
+      && global_options.x_flag_wrapv)
+    append_to_collect_gcc_options (&temporary_obstack, &first_p, "-fwrapv");
+  if (!global_options_set.x_flag_trapv
+      && !global_options.x_flag_trapv)
+    append_to_collect_gcc_options (&temporary_obstack, &first_p, "-fno-trapv");
+  if (!global_options_set.x_flag_strict_overflow
+      && !global_options.x_flag_strict_overflow)
+    append_to_collect_gcc_options (&temporary_obstack, &first_p,
+			       "-fno-strict-overflow");
 
   /* Output explicitly passed options.  */
   for (i = 1; i < save_decoded_options_count; ++i)
diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c
index 5798a81f958..b17945a2ffe 100644
--- a/gcc/lto-wrapper.c
+++ b/gcc/lto-wrapper.c
@@ -422,6 +422,8 @@ merge_and_complain (struct cl_decoded_option **decoded_options,
 	    append_option (decoded_options, decoded_options_count, foption);
 	  break;
 
+	case OPT_ftrapv:
+	case OPT_fstrict_overflow:
 	case OPT_ffp_contract_:
 	  /* For selected options we can merge conservatively.  */
 	  for (j = 0; j < *decoded_options_count; ++j)
@@ -429,11 +431,25 @@ merge_and_complain (struct cl_decoded_option **decoded_options,
 	      break;
 	  if (j == *decoded_options_count)
 	    append_option (decoded_options, decoded_options_count, foption);
-	  /* FP_CONTRACT_OFF < FP_CONTRACT_ON < FP_CONTRACT_FAST.  */
+	  /* FP_CONTRACT_OFF < FP_CONTRACT_ON < FP_CONTRACT_FAST,
+	     -fno-trapv < -ftrapv,
+	     -fno-strict-overflow < -fstrict-overflow  */
 	  else if (foption->value < (*decoded_options)[j].value)
 	    (*decoded_options)[j] = *foption;
 	  break;
 
+	case OPT_fwrapv:
+	  /* For selected options we can merge conservatively.  */
+	  for (j = 0; j < *decoded_options_count; ++j)
+	    if ((*decoded_options)[j].opt_index == foption->opt_index)
+	      break;
+	  if (j == *decoded_options_count)
+	    append_option (decoded_options, decoded_options_count, foption);
+	  /* -fwrapv > -fno-wrapv.  */
+	  else if (foption->value > (*decoded_options)[j].value)
+	    (*decoded_options)[j] = *foption;
+	  break;
+
 	case OPT_freg_struct_return:
 	case OPT_fpcc_struct_return:
 	  for (j = 0; j < *decoded_options_count; ++j)
@@ -591,6 +607,9 @@ run_gcc (unsigned argc, char *argv[])
 	case OPT_freg_struct_return:
 	case OPT_fpcc_struct_return:
 	case OPT_ffp_contract_:
+	case OPT_fwrapv:
+	case OPT_ftrapv:
+	case OPT_fstrict_overflow:
 	  break;
 
 	default: