From 6d6af2565ff593e3892e1aa0de4e404088c3b5f5 Mon Sep 17 00:00:00 2001 From: Alexander Kuechler Date: Thu, 24 Oct 2024 14:45:30 +0200 Subject: [PATCH] Remove useless stuff from ControlflowSensitiveDFGPass --- .../cpg/passes/ControlFlowSensitiveDFGPass.kt | 34 ++++--------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/ControlFlowSensitiveDFGPass.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/ControlFlowSensitiveDFGPass.kt index f8d538b404..1aca6d4fa9 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/ControlFlowSensitiveDFGPass.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/ControlFlowSensitiveDFGPass.kt @@ -363,18 +363,19 @@ open class ControlFlowSensitiveDFGPass(ctx: TranslationContext) : EOGStarterPass } } else if (currentNode is ComprehensionExpression) { val iterable = currentNode.iterable as? Expression - val (writtenTo, writtenTo2) = + val writtenTo = when (val variable = currentNode.variable) { is DeclarationStatement -> { if (variable.isSingleDeclaration()) { - Pair(variable.singleDeclaration, null) - } else if (variable.declarations.size == 2) { - Pair(variable.declarations.first(), variable.declarations.last()) + variable.singleDeclaration } else { - Pair(null, null) + log.error( + "Cannot handle multiple declarations in the ComprehensionExpresdsion: Node $currentNode" + ) + null } } - else -> Pair(currentNode.variable, null) + else -> currentNode.variable } // We wrote something to this variable declaration writtenTo?.let { @@ -398,27 +399,6 @@ open class ControlFlowSensitiveDFGPass(ctx: TranslationContext) : EOGStarterPass PowersetLattice(identitySetOf(writtenTo)) } } - writtenTo2?.let { - val writtenDeclaration2 = - when (writtenTo2) { - is Declaration -> writtenTo2 - is Reference -> writtenTo2.refersTo - else -> { - log.error( - "The variable of type ${writtenTo2.javaClass} is not yet supported in the ComprehensionExpression" - ) - null - } - } - - iterable?.let { - state.push(writtenTo2, PowersetLattice(identitySetOf(iterable))) - // Add the variable declaration (or the reference) to the list of previous - // write nodes in this path - state.declarationsState[writtenDeclaration2] = - PowersetLattice(identitySetOf(writtenTo2)) - } - } } else if (currentNode is ForEachStatement && currentNode.variable != null) { // The VariableDeclaration in the ForEachStatement doesn't have an initializer, so // the "normal" case won't work. We handle this case separately here...