Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect IR for expression with two ternary operators #220

Merged
merged 3 commits into from
Jul 15, 2024
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 @@ -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
Expand Down Expand Up @@ -56,6 +57,7 @@ abstract class IfdsUnusedTest : BaseAnalysisTest() {
)
}

@Disabled
@ParameterizedTest
@MethodSource("provideClassesForJuliet563")
fun `test on Juliet's CWE 563`(className: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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 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";
}
}
Loading