Creating deep copy of local function declaration instructions in CFA, regression test #KT-10243 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
36206ddf6d
commit
60e457167d
@@ -66,4 +66,6 @@ public interface Pseudocode {
|
||||
List<? extends Instruction> getUsages(@Nullable PseudoValue value);
|
||||
|
||||
boolean isSideEffectFree(@NotNull Instruction instruction);
|
||||
|
||||
Pseudocode copy();
|
||||
}
|
||||
|
||||
@@ -458,6 +458,41 @@ public class PseudocodeImpl implements Pseudocode {
|
||||
return mutableInstructionList.get(targetPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PseudocodeImpl copy() {
|
||||
PseudocodeImpl result = new PseudocodeImpl(correspondingElement);
|
||||
result.repeatWhole(this);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void repeatWhole(PseudocodeImpl originalPseudocode) {
|
||||
Map<Label, Label> originalToCopy = Maps.newLinkedHashMap();
|
||||
Multimap<Instruction, Label> originalLabelsForInstruction = HashMultimap.create();
|
||||
int labelCount = 0;
|
||||
for (PseudocodeLabel label : originalPseudocode.labels) {
|
||||
originalToCopy.put(label, label.copy(labelCount++));
|
||||
originalLabelsForInstruction.put(getJumpTarget(label), label);
|
||||
}
|
||||
for (Label label : originalToCopy.values()) {
|
||||
labels.add((PseudocodeLabel) label);
|
||||
}
|
||||
for (Instruction originalInstruction : originalPseudocode.mutableInstructionList) {
|
||||
repeatLabelsBindingForInstruction(originalInstruction, originalToCopy, originalLabelsForInstruction);
|
||||
Instruction copy = copyInstruction(originalInstruction, originalToCopy);
|
||||
addInstruction(copy);
|
||||
if (originalInstruction == originalPseudocode.errorInstruction && copy instanceof SubroutineExitInstruction) {
|
||||
errorInstruction = (SubroutineExitInstruction) copy;
|
||||
}
|
||||
if (originalInstruction == originalPseudocode.exitInstruction && copy instanceof SubroutineExitInstruction) {
|
||||
exitInstruction = (SubroutineExitInstruction) copy;
|
||||
}
|
||||
if (originalInstruction == originalPseudocode.sinkInstruction && copy instanceof SubroutineSinkInstruction) {
|
||||
sinkInstruction = (SubroutineSinkInstruction) copy;
|
||||
}
|
||||
}
|
||||
parent = originalPseudocode.parent;
|
||||
}
|
||||
|
||||
public int repeatPart(@NotNull Label startLabel, @NotNull Label finishLabel, int labelCount) {
|
||||
PseudocodeImpl originalPseudocode = ((PseudocodeLabel) startLabel).getPseudocode();
|
||||
|
||||
|
||||
+1
-1
@@ -57,5 +57,5 @@ public class LocalFunctionDeclarationInstruction(
|
||||
override fun toString(): String = "d(${render(element)})"
|
||||
|
||||
override fun createCopy(): InstructionImpl =
|
||||
LocalFunctionDeclarationInstruction(element, body, lexicalScope)
|
||||
LocalFunctionDeclarationInstruction(element, body.copy(), lexicalScope)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
val f: Boolean = true
|
||||
private fun doUpdateRegularTasks() {
|
||||
try {
|
||||
while (f) {
|
||||
val xmlText = <!UNRESOLVED_REFERENCE!>getText<!>()
|
||||
if (<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>xmlText<!> <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>==<!> null) {}
|
||||
else {
|
||||
<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>xmlText<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>value<!> = 0 // !!!
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
finally {
|
||||
fun execute() {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
public val f: kotlin.Boolean = true
|
||||
private fun doUpdateRegularTasks(): kotlin.Unit
|
||||
@@ -12552,6 +12552,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt10243.kt")
|
||||
public void testKt10243() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/kt10243.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt127.kt")
|
||||
public void testKt127() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/regressions/kt127.kt");
|
||||
|
||||
Reference in New Issue
Block a user