stfc / PSyclone

Domain-specific compiler and code transformation system for Finite Difference/Volume/Element Earth-system models in Fortran
BSD 3-Clause "New" or "Revised" License
107 stars 29 forks source link

DefinitionUseChain doesn't check if a variable is written to in all routes through an if statement. #2760

Open LonelyCat124 opened 4 weeks ago

LonelyCat124 commented 4 weeks ago

At the moment if we have code like:

    a = 1
    b = a + c
    if ( d > e) then
        a = 3
    else
        a = 4
    end if
    b = a + d   

Searching for forward accesses from a=1 will find b = a + d (as well as the prior accesses to a. In this case, we could use the knowledge of the code structure to know that a is always written to inside the if statement regardless of the condition result, so b = a + d is never going to use the write from a=1. This is not a bug as it won't cause incorrect code generation for anything we plan to use this from, but it is over-cautious and could be improved in the future.