From f5feb3bf33f65187c11aa21204b18677b4dcf289 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Fri, 5 Sep 2014 15:45:37 +0400 Subject: [PATCH] Fixed: label copies should be added to all labels --- .../jet/lang/cfg/pseudocode/PseudocodeImpl.java | 5 ++++- .../cfg/controlStructures/Finally.instructions | 8 +++++++- .../FinallyTestCopy.instructions | 15 ++++++++++++++- .../testData/cfg/tailCalls/finally.instructions | 3 ++- .../cfg/tailCalls/finallyWithReturn.instructions | 3 ++- .../cfg/tailCalls/tryCatchFinally.instructions | 3 ++- 6 files changed, 31 insertions(+), 6 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/PseudocodeImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/PseudocodeImpl.java index 06037af052c..6df1061514a 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/PseudocodeImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/PseudocodeImpl.java @@ -460,7 +460,7 @@ public class PseudocodeImpl implements Pseudocode { Integer finishIndex = ((PseudocodeLabel) finishLabel).getTargetInstructionIndex(); assert finishIndex != null; - Map originalToCopy = Maps.newHashMap(); + Map originalToCopy = Maps.newLinkedHashMap(); Multimap originalLabelsForInstruction = HashMultimap.create(); for (PseudocodeLabel label : labels) { Integer index = label.getTargetInstructionIndex(); @@ -472,6 +472,9 @@ public class PseudocodeImpl implements Pseudocode { originalLabelsForInstruction.put(getJumpTarget(label), label); } } + for (Label label : originalToCopy.values()) { + labels.add((PseudocodeLabel) label); + } for (int index = startIndex; index < finishIndex; index++) { Instruction originalInstruction = mutableInstructionList.get(index); repeatLabelsBindingForInstruction(originalInstruction, originalToCopy, originalLabelsForInstruction); diff --git a/compiler/testData/cfg/controlStructures/Finally.instructions b/compiler/testData/cfg/controlStructures/Finally.instructions index e4071060a54..4fde7c0b147 100644 --- a/compiler/testData/cfg/controlStructures/Finally.instructions +++ b/compiler/testData/cfg/controlStructures/Finally.instructions @@ -22,6 +22,7 @@ L4 [start finally]: L5 [finish finally]: 2 jmp(error) NEXT:[] L3 [skipFinallyToErrorBlock]: +L6 [copy of L2, onExceptionToFinallyBlock]: 3 mark({ 2 }) PREV:[jmp(L3)] r(2) -> 2 merge(try { 1 } finally { 2 }|) -> @@ -119,6 +120,7 @@ L9 [start finally]: L10 [finish finally]: 2 jmp(error) NEXT:[] L8 [skipFinallyToErrorBlock]: +L11 [copy of L2, onExceptionToFinallyBlock]: 3 mark({ 2 }) PREV:[jmp(L8)] r(2) -> 2 merge(try { 1 @l{ () -> if (2 > 3) { return@l } } } finally { 2 }|) -> @@ -363,6 +365,7 @@ L11 [start finally]: L12 [finish finally]: 2 jmp(error) NEXT:[] L10 [skipFinallyToErrorBlock]: +L13 [copy of L2, onExceptionToFinallyBlock]: 3 mark({ 2 }) PREV:[jmp(L10)] r(2) -> 2 merge(try { @l while(true) { 1 if (2 > 3) { break @l } } 5 } finally { 2 }|) -> @@ -427,6 +430,7 @@ L11 [start finally]: L12 [finish finally]: 2 jmp(error) NEXT:[] L10 [skipFinallyToErrorBlock]: +L13 [copy of L2, onExceptionToFinallyBlock]: 3 mark({ 2 }) PREV:[jmp(L10)] r(2) -> 2 merge(try { @l while(true) { 1 if (2 > 3) { break @l } } } finally { 2 }|!) -> @@ -577,6 +581,7 @@ L11 [start finally]: L12 [finish finally]: 2 jmp(error) NEXT:[] L10 [skipFinallyToErrorBlock]: +L13 [copy of L2, onExceptionToFinallyBlock]: 3 mark({ 2 }) PREV:[jmp(L10)] r(2) -> 2 merge(try { @l for (i in 1..a) { 1 if (2 > 3) { continue @l } } 5 } finally { 2 }|) -> @@ -650,6 +655,7 @@ L11 [start finally]: L12 [finish finally]: 2 jmp(error) NEXT:[] L10 [skipFinallyToErrorBlock]: +L13 [copy of L2, onExceptionToFinallyBlock]: 3 mark({ 2 }) PREV:[jmp(L10)] r(2) -> 2 merge(try { @l for (i in 1..a) { 1 if (2 > 3) { continue @l } } } finally { 2 }|!) -> @@ -979,4 +985,4 @@ error: PREV:[] sink: PREV:[, ] -===================== \ No newline at end of file +===================== diff --git a/compiler/testData/cfg/controlStructures/FinallyTestCopy.instructions b/compiler/testData/cfg/controlStructures/FinallyTestCopy.instructions index 8d016253a6f..0bc3f40d5a5 100644 --- a/compiler/testData/cfg/controlStructures/FinallyTestCopy.instructions +++ b/compiler/testData/cfg/controlStructures/FinallyTestCopy.instructions @@ -107,6 +107,7 @@ L7 [start finally]: L8 [finish finally]: - 2 jmp(error) NEXT:[] PREV:[] L6 [skipFinallyToErrorBlock]: +L9 [copy of L3, onExceptionToFinallyBlock]: 3 mark({ return 1 }) PREV:[jmp(L6)] r(1) -> ret(*|) L1 NEXT:[] @@ -190,6 +191,7 @@ L14 ['if' expression result]: L15 [finish finally]: - 3 jmp(error) NEXT:[] PREV:[] L11 [skipFinallyToErrorBlock]: +L16 [copy of L8, onExceptionToFinallyBlock]: 4 mark({ if (cond()) return else continue }) PREV:[jmp(L11)] mark(if (cond()) return else continue) mark(cond()) @@ -197,7 +199,9 @@ L11 [skipFinallyToErrorBlock]: jf(L17|) NEXT:[jmp(L6), ret L1] ret L1 NEXT:[] - jmp(L18) NEXT:[merge(if (cond()) return else continue|!, !) -> ] PREV:[] +L17 [copy of L13, else branch]: jmp(L6) NEXT:[mark(cond())] PREV:[jf(L17|)] +L18 [copy of L14, 'if' expression result]: - merge(if (cond()) return else continue|!, !) -> PREV:[] - 3 merge(try { doSmth() } catch (e: NullPointerException) { doSmth1() } catch (e: Exception) { doSmth2() } finally { if (cond()) return else continue }|, , ) -> PREV:[] - 2 jmp(L2) NEXT:[mark(cond())] PREV:[] @@ -273,12 +277,18 @@ L11 [body exit point]: L13 [finish finally]: 2 jmp(error) NEXT:[] L6 [skipFinallyToErrorBlock]: +L14 [copy of L3, onExceptionToFinallyBlock]: 3 mark({ while (cond()); }) PREV:[jmp(L6)] +L15 [copy of L8, loop entry point]: +L19 [copy of L12, condition entry point]: mark(cond()) PREV:[mark({ while (cond()); }), jmp(L15)] call(cond(), cond) -> mark(while (cond())) jf(L16|) NEXT:[read (Unit), jmp(L15)] +L17 [copy of L10, body entry point]: jmp(L15) NEXT:[mark(cond())] +L16 [copy of L9, loop exit point]: +L18 [copy of L11, body exit point]: read (Unit) PREV:[jf(L16|)] 2 merge(try { doSmth() } catch (e: NullPointerException) { doSmth1() } catch (e: Exception) { doSmth2() } finally { while (cond()); }|, , ) -> L1: @@ -330,6 +340,7 @@ L6 ['if' expression result]: L7 [finish finally]: 2 jmp(error) NEXT:[] L3 [skipFinallyToErrorBlock]: +L8 [copy of L2, onExceptionToFinallyBlock]: 3 mark({ if(list != null) { } }) PREV:[jmp(L3)] mark(if(list != null) { }) r(list) -> @@ -340,7 +351,9 @@ L3 [skipFinallyToErrorBlock]: 4 mark({ }) read (Unit) 3 jmp(L10) NEXT:[merge(if(list != null) { }|!) -> ] +L9 [copy of L5, else branch]: read (Unit) PREV:[jf(L9|)] +L10 [copy of L6, 'if' expression result]: merge(if(list != null) { }|!) -> PREV:[jmp(L10), read (Unit)] 2 merge(try { doSmth() } finally { if(list != null) { } }|) -> L1: @@ -349,4 +362,4 @@ error: PREV:[jmp(error)] sink: PREV:[, ] -===================== \ No newline at end of file +===================== diff --git a/compiler/testData/cfg/tailCalls/finally.instructions b/compiler/testData/cfg/tailCalls/finally.instructions index 66951e726e1..e266b16db59 100644 --- a/compiler/testData/cfg/tailCalls/finally.instructions +++ b/compiler/testData/cfg/tailCalls/finally.instructions @@ -23,6 +23,7 @@ L4 [start finally]: L5 [finish finally]: 2 jmp(error) NEXT:[] L3 [skipFinallyToErrorBlock]: +L6 [copy of L2, onExceptionToFinallyBlock]: 3 mark({ test() }) PREV:[jmp(L3)] mark(test()) call(test(), test) -> @@ -33,4 +34,4 @@ error: PREV:[jmp(error)] sink: PREV:[, ] -===================== \ No newline at end of file +===================== diff --git a/compiler/testData/cfg/tailCalls/finallyWithReturn.instructions b/compiler/testData/cfg/tailCalls/finallyWithReturn.instructions index 4ccff7c5e4f..a9a02389f11 100644 --- a/compiler/testData/cfg/tailCalls/finallyWithReturn.instructions +++ b/compiler/testData/cfg/tailCalls/finallyWithReturn.instructions @@ -24,6 +24,7 @@ L4 [start finally]: L5 [finish finally]: - 2 jmp(error) NEXT:[] PREV:[] L3 [skipFinallyToErrorBlock]: +L6 [copy of L2, onExceptionToFinallyBlock]: 3 mark({ return test() }) PREV:[jmp(L3)] mark(test()) call(test(), test) -> @@ -35,4 +36,4 @@ error: PREV:[] sink: PREV:[, ] -===================== \ No newline at end of file +===================== diff --git a/compiler/testData/cfg/tailCalls/tryCatchFinally.instructions b/compiler/testData/cfg/tailCalls/tryCatchFinally.instructions index 12083fdaee1..35cb888cde1 100644 --- a/compiler/testData/cfg/tailCalls/tryCatchFinally.instructions +++ b/compiler/testData/cfg/tailCalls/tryCatchFinally.instructions @@ -37,6 +37,7 @@ L6 [start finally]: L7 [finish finally]: 2 jmp(error) NEXT:[] L5 [skipFinallyToErrorBlock]: +L8 [copy of L3, onExceptionToFinallyBlock]: 3 mark({ test() }) PREV:[jmp(L5)] mark(test()) call(test(), test) -> @@ -47,4 +48,4 @@ error: PREV:[jmp(error)] sink: PREV:[, ] -===================== \ No newline at end of file +=====================