IR: fix offsets in irTemporary
The variable generated by IrStatementBuilder.irTemporary doesn't inherit startOffset and endOffset from the builder. In particular, as a result, temporary variables generated for elvis operator left operand have UNDEFINED_OFFSET. Additionally, ProvisionalFunctionExpressionLowering copies the offsets of a variable to lowered lambda in the variable initializer. With the problem described above, this causes invalid debug information in Kotlin/Native, see KT-49360. Fix irTemporary by using builder's offsets for the variable. ^KT-49360 Fixed
This commit is contained in:
committed by
Space
parent
fb859c0270
commit
2f5706597a
@@ -45,7 +45,11 @@ fun <T : IrElement> IrStatementsBuilder<T>.irTemporary(
|
||||
irType: IrType = value?.type!!, // either value or irType should be supplied at callsite
|
||||
isMutable: Boolean = false,
|
||||
): IrVariable {
|
||||
val temporary = scope.createTemporaryVariableDeclaration(irType, nameHint, isMutable)
|
||||
val temporary = scope.createTemporaryVariableDeclaration(
|
||||
irType, nameHint, isMutable,
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset
|
||||
)
|
||||
value?.let { temporary.initializer = it }
|
||||
+temporary
|
||||
return temporary
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun intN(): Int? = null
|
||||
|
||||
fun test() = intN() ?: 1
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
@0:0..3:0 FILE fqName:<root> fileName:/elvis.kt
|
||||
@0:0..23 FUN name:intN visibility:public modality:FINAL <> () returnType:kotlin.Int?
|
||||
@0:19..23 BLOCK_BODY
|
||||
@0:23..23 RETURN type=kotlin.Nothing from='public final fun intN (): kotlin.Int? declared in <root>'
|
||||
@0:19..23 CONST Null type=kotlin.Nothing? value=null
|
||||
@2:0..24 FUN name:test visibility:public modality:FINAL <> () returnType:kotlin.Int
|
||||
@2:13..24 BLOCK_BODY
|
||||
@2:24..24 RETURN type=kotlin.Nothing from='public final fun test (): kotlin.Int declared in <root>'
|
||||
@2:13..24 BLOCK type=kotlin.Int origin=ELVIS
|
||||
@2:13..24 VAR IR_TEMPORARY_VARIABLE name:tmp0_elvis_lhs type:kotlin.Int? [val]
|
||||
@2:13..19 CALL 'public final fun intN (): kotlin.Int? declared in <root>' type=kotlin.Int? origin=null
|
||||
@2:13..24 WHEN type=kotlin.Int origin=null
|
||||
@2:13..24 BRANCH
|
||||
@2:13..24 CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
|
||||
@2:13..24 GET_VAR 'val tmp0_elvis_lhs: kotlin.Int? [val] declared in <root>.test' type=kotlin.Int? origin=null
|
||||
@2:13..24 CONST Null type=kotlin.Nothing? value=null
|
||||
@2:23..24 CONST Int type=kotlin.Int value=1
|
||||
@2:13..24 BRANCH
|
||||
@2:13..24 CONST Boolean type=kotlin.Boolean value=true
|
||||
@2:13..24 GET_VAR 'val tmp0_elvis_lhs: kotlin.Int? [val] declared in <root>.test' type=kotlin.Int? origin=null
|
||||
@@ -0,0 +1,6 @@
|
||||
fun test() {
|
||||
var x = 0
|
||||
var y = 0
|
||||
y = x++
|
||||
y = x--
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
@0:0..6:0 FILE fqName:<root> fileName:/postfixIncrementDecrement.kt
|
||||
@0:0..5:1 FUN name:test visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||
@0:11..5:1 BLOCK_BODY
|
||||
@1:4..13 VAR name:x type:kotlin.Int [var]
|
||||
@1:12..13 CONST Int type=kotlin.Int value=0
|
||||
@2:4..13 VAR name:y type:kotlin.Int [var]
|
||||
@2:12..13 CONST Int type=kotlin.Int value=0
|
||||
@3:4..5 SET_VAR 'var y: kotlin.Int [var] declared in <root>.test' type=kotlin.Unit origin=EQ
|
||||
@3:8..11 BLOCK type=kotlin.Int origin=POSTFIX_INCR
|
||||
@3:8..11 VAR IR_TEMPORARY_VARIABLE name:tmp0 type:kotlin.Int [val]
|
||||
@3:8..9 GET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Int origin=POSTFIX_INCR
|
||||
@3:8..9 SET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Unit origin=POSTFIX_INCR
|
||||
@3:8..11 CALL 'public final fun inc (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=POSTFIX_INCR
|
||||
@3:8..11 GET_VAR 'val tmp0: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null
|
||||
@3:8..11 GET_VAR 'val tmp0: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null
|
||||
@4:4..5 SET_VAR 'var y: kotlin.Int [var] declared in <root>.test' type=kotlin.Unit origin=EQ
|
||||
@4:8..11 BLOCK type=kotlin.Int origin=POSTFIX_DECR
|
||||
@4:8..11 VAR IR_TEMPORARY_VARIABLE name:tmp1 type:kotlin.Int [val]
|
||||
@4:8..9 GET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Int origin=POSTFIX_DECR
|
||||
@4:8..9 SET_VAR 'var x: kotlin.Int [var] declared in <root>.test' type=kotlin.Unit origin=POSTFIX_DECR
|
||||
@4:8..11 CALL 'public final fun dec (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=POSTFIX_DECR
|
||||
@4:8..11 GET_VAR 'val tmp1: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null
|
||||
@4:8..11 GET_VAR 'val tmp1: kotlin.Int [val] declared in <root>.test' type=kotlin.Int origin=null
|
||||
+10
@@ -39,6 +39,11 @@ public class IrSourceRangesTestCaseGenerated extends AbstractIrSourceRangesTestC
|
||||
runTest("compiler/testData/ir/sourceRanges/comments.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("elvis.kt")
|
||||
public void testElvis() throws Exception {
|
||||
runTest("compiler/testData/ir/sourceRanges/elvis.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt17108.kt")
|
||||
public void testKt17108() throws Exception {
|
||||
runTest("compiler/testData/ir/sourceRanges/kt17108.kt");
|
||||
@@ -49,6 +54,11 @@ public class IrSourceRangesTestCaseGenerated extends AbstractIrSourceRangesTestC
|
||||
runTest("compiler/testData/ir/sourceRanges/kt24258.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("postfixIncrementDecrement.kt")
|
||||
public void testPostfixIncrementDecrement() throws Exception {
|
||||
runTest("compiler/testData/ir/sourceRanges/postfixIncrementDecrement.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/ir/sourceRanges/declarations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user