diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index f7faf892a9dc9f14080550b6ba502a2d6a562a99..fdfca8ba6bc3768319e1bb2333470caf2e55142d 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2018-10-24  Alexandre Oliva <aoliva@redhat.com>
+
+	* gimple-ssa-isolate-paths.c
+	(find_implicit_erroneous_behavior): Do not change code if the
+	pass is running for warnings only.
+	(find_explicit_erroneous_behavior): Likewise.
+
 2018-10-24  Michael Meissner  <meissner@linux.ibm.com>
 
 	* config/rs6000/rs6000.c (TARGET_MANGLE_DECL_ASSEMBLER_NAME):
diff --git a/gcc/gimple-ssa-isolate-paths.c b/gcc/gimple-ssa-isolate-paths.c
index e1fab61bedabedc078d5fcf034e2c1aaffdcc651..880836c21aa79ac4af38d233cd6b94220b2075c4 100644
--- a/gcc/gimple-ssa-isolate-paths.c
+++ b/gcc/gimple-ssa-isolate-paths.c
@@ -431,7 +431,9 @@ find_implicit_erroneous_behavior (void)
 					"declared here");
 			  }
 
-			  if (gimple_bb (use_stmt) == bb)
+			  if ((flag_isolate_erroneous_paths_dereference
+			       || flag_isolate_erroneous_paths_attribute)
+			      && gimple_bb (use_stmt) == bb)
 			    {
 			      duplicate = isolate_path (bb, duplicate, e,
 							use_stmt, lhs, true);
@@ -553,9 +555,16 @@ find_explicit_erroneous_behavior (void)
 			  inform (DECL_SOURCE_LOCATION(valbase),
 				  "declared here");
 		      }
-		      tree zero = build_zero_cst (TREE_TYPE (val));
-		      gimple_return_set_retval (return_stmt, zero);
-		      update_stmt (stmt);
+
+		      /* Do not modify code if the user only asked for
+			 warnings.  */
+		      if (flag_isolate_erroneous_paths_dereference
+			  || flag_isolate_erroneous_paths_attribute)
+			{
+			  tree zero = build_zero_cst (TREE_TYPE (val));
+			  gimple_return_set_retval (return_stmt, zero);
+			  update_stmt (stmt);
+			}
 		    }
 		}
 	    }