Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1123,12 +1123,12 @@ class RawInstListBuilder(
val expr = when (opcode) {
Opcodes.IFNULL -> JcRawEqExpr(boolTypeName, rhv, JcRawNull())
Opcodes.IFNONNULL -> JcRawNeqExpr(boolTypeName, rhv, JcRawNull())
Opcodes.IFEQ -> JcRawEqExpr(boolTypeName, JcRawZero(rhv.typeName), rhv)
Opcodes.IFNE -> JcRawNeqExpr(boolTypeName, JcRawZero(rhv.typeName), rhv)
Opcodes.IFLT -> JcRawLtExpr(boolTypeName, JcRawZero(rhv.typeName), rhv)
Opcodes.IFGE -> JcRawGeExpr(boolTypeName, JcRawZero(rhv.typeName), rhv)
Opcodes.IFGT -> JcRawGtExpr(boolTypeName, JcRawZero(rhv.typeName), rhv)
Opcodes.IFLE -> JcRawLeExpr(boolTypeName, JcRawZero(rhv.typeName), rhv)
Opcodes.IFEQ -> JcRawEqExpr(boolTypeName, rhv, JcRawZero(rhv.typeName))
Opcodes.IFNE -> JcRawNeqExpr(boolTypeName, rhv, JcRawZero(rhv.typeName))
Opcodes.IFLT -> JcRawLtExpr(boolTypeName, rhv, JcRawZero(rhv.typeName))
Opcodes.IFGE -> JcRawGeExpr(boolTypeName, rhv, JcRawZero(rhv.typeName))
Opcodes.IFGT -> JcRawGtExpr(boolTypeName, rhv, JcRawZero(rhv.typeName))
Opcodes.IFLE -> JcRawLeExpr(boolTypeName, rhv, JcRawZero(rhv.typeName))
Opcodes.IF_ICMPEQ -> JcRawEqExpr(boolTypeName, pop(), rhv)
Opcodes.IF_ICMPNE -> JcRawNeqExpr(boolTypeName, pop(), rhv)
Opcodes.IF_ICMPLT -> JcRawLtExpr(boolTypeName, pop(), rhv)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ import org.jacodb.api.JcClassOrInterface
import org.jacodb.api.JcClassProcessingTask
import org.jacodb.api.JcMethod
import org.jacodb.api.RegisteredLocation
import org.jacodb.api.cfg.JcArgument
import org.jacodb.api.cfg.JcAssignInst
import org.jacodb.api.cfg.JcGeExpr
import org.jacodb.api.cfg.JcGtExpr
import org.jacodb.api.cfg.JcIfInst
import org.jacodb.api.cfg.JcInt
import org.jacodb.api.cfg.JcLocalVar
import org.jacodb.api.ext.cfg.callExpr
import org.jacodb.api.ext.cfg.locals
Expand Down Expand Up @@ -58,6 +63,27 @@ class InstructionsTest : BaseTest() {
assertEquals("%1", (assign.rhv as JcLocalVar).name)
}

@Test
fun `cmp insts`() {
val clazz = cp.findClass<Conditionals>()
val method = clazz.declaredMethods.first { it.name == "main" }
val instructions = method.instList.instructions
val cmpExprs = instructions.filterIsInstance<JcIfInst>().map { it.condition }
assertEquals(4, cmpExprs.size)

val geZero = cmpExprs[0] as JcGeExpr
assertEquals(0 to 0, (geZero.lhv as JcArgument).index to (geZero.rhv as JcInt).value)

val gtZero = cmpExprs[1] as JcGtExpr
assertEquals(0 to 0, (gtZero.lhv as JcArgument).index to (gtZero.rhv as JcInt).value)

val geOther = cmpExprs[2] as JcGeExpr
assertEquals(0 to 1, (geOther.lhv as JcArgument).index to (geOther.rhv as JcArgument).index)

val gtOther = cmpExprs[3] as JcGtExpr
assertEquals(0 to 1, (gtOther.lhv as JcArgument).index to (gtOther.rhv as JcArgument).index)
}

@Test
fun `null ref test`() {
val clazz = cp.findClass<DataHandler>()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2022 UnitTestBot contributors (utbot.org)
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jacodb.testing.cfg;

public class Conditionals {
void main(int x, int y) {
if (x < 0) {
System.out.println("< 0");
}
if (x <= 0) {
System.out.println("<= 0");
}
if (x < y) {
System.out.println("<");
}
if (x <= y) {
System.out.println("<=");
}
}
}