Merge "Don't collapse goto-return if the return is affected by a debug position."
diff --git a/src/main/java/com/android/tools/r8/ir/code/Instruction.java b/src/main/java/com/android/tools/r8/ir/code/Instruction.java
index de198c9..466a455 100644
--- a/src/main/java/com/android/tools/r8/ir/code/Instruction.java
+++ b/src/main/java/com/android/tools/r8/ir/code/Instruction.java
@@ -142,6 +142,9 @@
 
   public void clearDebugValues() {
     if (debugValues != null) {
+      for (Value debugValue : debugValues) {
+        debugValue.removeDebugUser(this);
+      }
       debugValues.clear();
     }
   }
diff --git a/src/main/java/com/android/tools/r8/ir/optimize/DeadCodeRemover.java b/src/main/java/com/android/tools/r8/ir/optimize/DeadCodeRemover.java
index 50f224c..ebf69b5 100644
--- a/src/main/java/com/android/tools/r8/ir/optimize/DeadCodeRemover.java
+++ b/src/main/java/com/android/tools/r8/ir/optimize/DeadCodeRemover.java
@@ -120,7 +120,7 @@
       // All users will be removed for this instruction. Eagerly clear them so further inspection
       // of this instruction during dead code elimination will terminate here.
       outValue.clearUsers();
-      iterator.remove();
+      iterator.removeOrReplaceByNop();
     }
   }