Fraunhofer-AISEC / cpg

A library to extract Code Property Graphs from C/C++, Java, Go, Python, Ruby and every other language through LLVM-IR.
https://fraunhofer-aisec.github.io/cpg/
Apache License 2.0
281 stars 62 forks source link

`variable` and `iterable` from `ForEachStatement` are not connected in DFG #1006

Closed seelchen closed 1 year ago

seelchen commented 1 year ago

Unexpected behavior

When analyzing code with a for each loop, there is no dataflow from the iterable to the variable of the ForEachStatement. The variable also has UninitializedValue as initializer which might be related to the missing dataflow.

Example

class For {
    public void forIterator() {
        int[] a = {1,2,3,4,5};
        for(int j : a) {
            System.out.println(j);
        }
    }
}

Changes to the configuration

TranslationConfiguration.builder()
            .defaultPasses()
            .defaultLanguages()
            .codeInNodes(true)
oxisto commented 1 year ago

Thanks for catching that. I have actually never seen this strange UninitializedValue expression. Seems to be a left over from some early days and should be removed.

z2Z6 commented 1 year ago

Hi @oxisto , Could you have a plan to add the dataflow from the variable(VariableDeclaration) of ForEachStatement to its DeclaredReferenceExpression in ForEachStatement. Now the dataflow from iterable to variable(DeclarationStatement) may has little significance.

oxisto commented 1 year ago

Hi @oxisto , Could you have a plan to add the dataflow from the variable(VariableDeclaration) of ForEachStatement to its DeclaredReferenceExpression in ForEachStatement. Now the dataflow from iterable to variable(DeclarationStatement) may has little significance.

I'll refer to the dataflow specialists @konradweiss and @KuechA :)

KuechA commented 1 year ago

Good catch, I'll look into it