From 59a7466759c93c5a96788b4db37df4afff62ad38 Mon Sep 17 00:00:00 2001 From: IlyaMuravjov Date: Fri, 16 Feb 2024 16:45:02 +0300 Subject: [PATCH 1/3] Add failing test for expression with two ternary operators --- .../jacodb/testing/cfg/InstructionsTest.kt | 5 +++ .../testing/cfg/TwoTernaryOperators.java | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 jacodb-core/src/testFixtures/java/org/jacodb/testing/cfg/TwoTernaryOperators.java diff --git a/jacodb-core/src/test/kotlin/org/jacodb/testing/cfg/InstructionsTest.kt b/jacodb-core/src/test/kotlin/org/jacodb/testing/cfg/InstructionsTest.kt index bb3296dbc..f1bf09fe4 100644 --- a/jacodb-core/src/test/kotlin/org/jacodb/testing/cfg/InstructionsTest.kt +++ b/jacodb-core/src/test/kotlin/org/jacodb/testing/cfg/InstructionsTest.kt @@ -339,6 +339,11 @@ class InstructionsTest : BaseInstructionsTest() { runTest(ArgAssignmentExample::class.java.name) } + @Test + fun `two ternary operators`() { + runTest(TwoTernaryOperators::class.java.name) + } + } fun JcMethod.dumpInstructions(): String { diff --git a/jacodb-core/src/testFixtures/java/org/jacodb/testing/cfg/TwoTernaryOperators.java b/jacodb-core/src/testFixtures/java/org/jacodb/testing/cfg/TwoTernaryOperators.java new file mode 100644 index 000000000..abc9e3b52 --- /dev/null +++ b/jacodb-core/src/testFixtures/java/org/jacodb/testing/cfg/TwoTernaryOperators.java @@ -0,0 +1,31 @@ +/* + * Copyright 2022 UnitTestBot contributors (utbot.org) + *

+ * 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 + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * 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 TwoTernaryOperators { + @SuppressWarnings("ConstantValue") + public int f() { + int i = Integer.parseInt("1"); + boolean b = Boolean.parseBoolean("true"); + return (b ? i : 0) + (!b ? i : 0); + } + + public String box() { + int result = f(); + return result == 1 ? "OK" : "BAD"; + } +} From d67ad23e6fea5292933db7004fc0d0079d3a8974 Mon Sep 17 00:00:00 2001 From: IlyaMuravjov Date: Fri, 16 Feb 2024 17:43:14 +0300 Subject: [PATCH 2/3] Fix mutually dependent assignments simplification --- jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/Simplifier.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/Simplifier.kt b/jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/Simplifier.kt index 33642c22e..1474e388f 100644 --- a/jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/Simplifier.kt +++ b/jacodb-core/src/main/kotlin/org/jacodb/impl/cfg/Simplifier.kt @@ -66,7 +66,7 @@ internal class Simplifier { val assignmentsMap = computeAssignments(instructionList) val replacements = buildMap { for ((to, froms) in assignmentsMap) { - if (froms.drop(1).any { it is JcRawLocalVar }) { + if (froms.size > 1) { continue } val firstFrom = (froms.first() as? JcRawLocalVar) ?: continue From dc2a7783d7484c20040e5b9536284ce83a74b606 Mon Sep 17 00:00:00 2001 From: IlyaMuravjov Date: Fri, 12 Jul 2024 19:43:22 +0300 Subject: [PATCH 3/3] Disable some `IfdsUnusedTest`s --- .../src/test/kotlin/org/jacodb/analysis/impl/IfdsUnusedTest.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jacodb-analysis/src/test/kotlin/org/jacodb/analysis/impl/IfdsUnusedTest.kt b/jacodb-analysis/src/test/kotlin/org/jacodb/analysis/impl/IfdsUnusedTest.kt index 3fbd43f9b..9655f259a 100644 --- a/jacodb-analysis/src/test/kotlin/org/jacodb/analysis/impl/IfdsUnusedTest.kt +++ b/jacodb-analysis/src/test/kotlin/org/jacodb/analysis/impl/IfdsUnusedTest.kt @@ -25,6 +25,7 @@ import org.jacodb.impl.features.Usages import org.jacodb.testing.WithDB import org.jacodb.testing.WithRAMDB import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.Arguments @@ -56,6 +57,7 @@ abstract class IfdsUnusedTest : BaseAnalysisTest() { ) } + @Disabled @ParameterizedTest @MethodSource("provideClassesForJuliet563") fun `test on Juliet's CWE 563`(className: String) {