Turn off optimizations in case of do-while presence

This commit is contained in:
Denis Zharkov
2017-09-26 13:02:23 +03:00
parent c31b5beb9e
commit a51078fda6
5 changed files with 15 additions and 5 deletions
@@ -38,6 +38,7 @@ private typealias ImmutableSet<T> = javaslang.collection.Set<T>
private typealias ImmutableHashSet<T> = javaslang.collection.HashSet<T>
class PseudocodeVariablesData(val pseudocode: Pseudocode, private val bindingContext: BindingContext) {
private val containsDoWhile = pseudocode.rootPseudocode.containsDoWhile
private val pseudocodeVariableDataCollector = PseudocodeVariableDataCollector(bindingContext, pseudocode)
private class VariablesForDeclaration(
@@ -107,7 +108,7 @@ class PseudocodeVariablesData(val pseudocode: Pseudocode, private val bindingCon
bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, variableDeclarationElement)
) ?: continue
if (isValWithTrivialInitializer(variableDeclarationElement, descriptor)) {
if (!containsDoWhile && isValWithTrivialInitializer(variableDeclarationElement, descriptor)) {
valsWithTrivialInitializer.add(descriptor)
}
else {
@@ -19,8 +19,8 @@ package org.jetbrains.kotlin.cfg.pseudocode
import com.intellij.util.containers.Stack
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.cfg.*
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction
import org.jetbrains.kotlin.cfg.pseudocode.instructions.BlockScope
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction
import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.*
import org.jetbrains.kotlin.cfg.pseudocode.instructions.jumps.*
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.*
@@ -29,7 +29,6 @@ import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import java.util.*
class ControlFlowInstructionsGenerator : ControlFlowBuilderAdapter() {
@@ -113,6 +112,10 @@ class ControlFlowInstructionsGenerator : ControlFlowBuilderAdapter() {
override fun createUnboundLabel(name: String): Label = pseudocode.createLabel("L" + labelCount++, name)
override fun enterLoop(expression: KtLoopExpression): LoopInfo {
if (expression is KtDoWhileExpression) {
(pseudocode.rootPseudocode as PseudocodeImpl).containsDoWhile = true
}
val info = LoopInfo(
expression,
createUnboundLabel("loop entry point"),
@@ -45,6 +45,9 @@ interface Pseudocode {
val enterInstruction: SubroutineEnterInstruction
val containsDoWhile: Boolean
val rootPseudocode: Pseudocode
fun getElementValue(element: KtElement?): PseudoValue?
fun getValueElements(value: PseudoValue?): List<KtElement>
@@ -77,6 +77,9 @@ class PseudocodeImpl(override val correspondingElement: KtElement) : Pseudocode
private var postPrecessed = false
override var containsDoWhile: Boolean = false
internal set
private fun getLocalDeclarations(pseudocode: Pseudocode): Set<LocalFunctionDeclarationInstruction> {
val localDeclarations = linkedSetOf<LocalFunctionDeclarationInstruction>()
for (instruction in (pseudocode as PseudocodeImpl).mutableInstructionList) {
@@ -88,7 +91,7 @@ class PseudocodeImpl(override val correspondingElement: KtElement) : Pseudocode
return localDeclarations
}
val rootPseudocode: Pseudocode
override val rootPseudocode: Pseudocode
get() {
var parent = parent
while (parent != null) {
@@ -2,5 +2,5 @@ fun test(cond1: Boolean) {
do {
if (cond1) continue
val cond2 = false
} while (cond2) // cond2 may be not defined here
} while (<!UNINITIALIZED_VARIABLE!>cond2<!>) // cond2 may be not defined here
}