PSyclone icon indicating copy to clipboard operation
PSyclone copied to clipboard

Copying a tree containing shadowed symbols may change semantics

Open arporter opened this issue 1 year ago • 0 comments

ScopingNode._refine_copy() uses replace_symbols_using to ensure that Symbols referred to in a sub-tree are updated. However, since replace_symbols_using only uses symbol names, this won't get the correct symbol if the PSyIR happens to have symbols shadowed in nested scopes. In practise, this isn't often a problem but it is easy to imagine a situation where it will break, e.g.:

  subroutine test
    integer :: a
    integer :: b = 1
    if condition then
      ! PSyIR declares a shadowed, locally-scoped a'
      a' = 1
      if condition2 then
        ! PSyIR declares a shadowed, locally-scoped b'
        b' = 2
        a = a' + b'

Here, the final assignment will end up being a' = a' + b' and thus the semantics of the code are changed. (Note that Fortran code is only used to illustrate the problem - it's not possible to create such a situation directly from actual Fortran because it doesn't support nested scopes*.)

  • apart from ASSOCIATE constructs and the PSyIR doesn't support those yet.

arporter avatar Jul 19 '24 12:07 arporter