From 725891a0a46961602cad6f81dd9c8f0ee3d93cea Mon Sep 17 00:00:00 2001
From: Michael Matz <matz@suse.de>
Date: Wed, 14 Nov 2018 15:43:54 +0000
Subject: [PATCH] re PR middle-end/86575 (-Wimplicit-fallthrough affects code
 generation)

Fix PR middle-end/86575

	PR middle-end/86575
	* gimplify.c (collect_fallthrough_labels): Add new argument,
	return location via that, don't modify statements.
	(warn_implicit_fallthrough_r): Adjust call, don't use
	statement location directly.

From-SVN: r266148
---
 gcc/ChangeLog  |  8 ++++++++
 gcc/gimplify.c | 15 ++++++++++-----
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 1a70b8ff591c..f83b0edda637 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2018-11-14  Michael Matz  <matz@suse.de>
+
+	PR middle-end/86575
+	* gimplify.c (collect_fallthrough_labels): Add new argument,
+	return location via that, don't modify statements.
+	(warn_implicit_fallthrough_r): Adjust call, don't use
+	statement location directly.
+
 2018-11-14  Richard Biener  <rguenther@suse.de>
 
 	PR middle-end/87985
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index ad7f824e0fa2..017dbbc37dcf 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -1963,10 +1963,12 @@ last_stmt_in_scope (gimple *stmt)
 
 static gimple *
 collect_fallthrough_labels (gimple_stmt_iterator *gsi_p,
-			    auto_vec <struct label_entry> *labels)
+			    auto_vec <struct label_entry> *labels,
+			    location_t *prevloc)
 {
   gimple *prev = NULL;
 
+  *prevloc = UNKNOWN_LOCATION;
   do
     {
       if (gimple_code (gsi_stmt (*gsi_p)) == GIMPLE_BIND)
@@ -2003,7 +2005,7 @@ collect_fallthrough_labels (gimple_stmt_iterator *gsi_p,
 	      /* It might be a label without a location.  Use the
 		 location of the scope then.  */
 	      if (!gimple_has_location (prev))
-		gimple_set_location (prev, bind_loc);
+		*prevloc = bind_loc;
 	    }
 	  gsi_next (gsi_p);
 	  continue;
@@ -2086,6 +2088,8 @@ collect_fallthrough_labels (gimple_stmt_iterator *gsi_p,
 	 && (gimple_code (gsi_stmt (*gsi_p)) != GIMPLE_LABEL
 	     || !gimple_has_location (gsi_stmt (*gsi_p))));
 
+  if (prev && gimple_has_location (prev))
+    *prevloc = gimple_location (prev);
   return prev;
 }
 
@@ -2182,7 +2186,8 @@ warn_implicit_fallthrough_r (gimple_stmt_iterator *gsi_p, bool *handled_ops_p,
 
 	/* Vector of labels that fall through.  */
 	auto_vec <struct label_entry> labels;
-	gimple *prev = collect_fallthrough_labels (gsi_p, &labels);
+	location_t prevloc;
+	gimple *prev = collect_fallthrough_labels (gsi_p, &labels, &prevloc);
 
 	/* There might be no more statements.  */
 	if (gsi_end_p (*gsi_p))
@@ -2210,8 +2215,8 @@ warn_implicit_fallthrough_r (gimple_stmt_iterator *gsi_p, bool *handled_ops_p,
 		     /* Try to be clever and don't warn when the statement
 			can't actually fall through.  */
 		     && gimple_stmt_may_fallthru (prev)
-		     && gimple_has_location (prev))
-	      warned_p = warning_at (gimple_location (prev),
+		     && prevloc != UNKNOWN_LOCATION)
+	      warned_p = warning_at (prevloc,
 				     OPT_Wimplicit_fallthrough_,
 				     "this statement may fall through");
 	    if (warned_p)
-- 
GitLab