Skip to content

Commit 378acbf

Browse files
committed
Minor. Clarify method patchOpcode contract
1 parent 2144976 commit 378acbf

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

compiler/backend/src/org/jetbrains/kotlin/codegen/BranchedValue.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,25 +210,32 @@ class NumberCompare(
210210
) : BranchedValue(left, right, operandType, NumberCompare.getNumberCompareOpcode(opToken)) {
211211

212212
override fun patchOpcode(opcode: Int, v: InstructionAdapter): Int {
213-
when (operandType) {
213+
// Opcode takes one int operand from the stack
214+
assert(opcode in IFEQ..IFLE) {
215+
"Opcode for comparing must be in range ${IFEQ..IFLE}, but $opcode was found"
216+
}
217+
218+
return when (operandType) {
214219
Type.FLOAT_TYPE, Type.DOUBLE_TYPE -> {
215220
if (opToken == KtTokens.GT || opToken == KtTokens.GTEQ) {
216221
v.cmpl(operandType)
217222
}
218223
else {
219224
v.cmpg(operandType)
220225
}
226+
227+
opcode
221228
}
222229
Type.LONG_TYPE -> {
223230
v.lcmp()
231+
232+
opcode
224233
}
225234
else -> {
226-
return opcode + (IF_ICMPEQ - IFEQ)
235+
opcode + (IF_ICMPEQ - IFEQ)
227236
}
228237
}
229-
return opcode
230238
}
231-
232239
companion object {
233240
fun getNumberCompareOpcode(opToken: IElementType): Int {
234241
return when (opToken) {
@@ -262,4 +269,4 @@ class ObjectCompare(
262269
}
263270
}
264271
}
265-
}
272+
}

0 commit comments

Comments
 (0)