PSyclone
PSyclone copied to clipboard
InlineTrans does not accept a 'clash' between two identical COMMON blocks
Hugo has reported:
Common Block
- Common block can be well inlined if there is no conflict.
code = """subroutine caller()
integer :: istr
integer :: iend
call foo(istr, iend)
end
subroutine foo(istr, iend)
integer :: istr
integer :: iend
call sub_foo(istr,iend)
end
subroutine sub_foo(istr,iend)
integer :: istr
integer :: iend
integer :: i
COMMON /ocean/ zeta
real zeta(10)
do i=istr, iend, 1
zeta(i)=zeta(i+1)
enddo
end
"""
def test_sub_foo_in_foo_and_inline_foo_in_caller():
"Contains common block"
psyir = FortranReader().psyir_from_source(code)
inline_trans = InlineTrans()
call = psyir.walk(Call)[1]
inline_trans.apply(call)
call = psyir.walk(Call)[0]
inline_trans.apply(call)
code_inlined = """subroutine caller()
implicit none
integer :: istr
integer :: iend
integer :: i
real, dimension(10) :: zeta
COMMON /ocean/ zeta
do i = istr, iend, 1
zeta(i) = zeta(i + 1)
enddo
end subroutine caller"""
[...]
- If there is a name clash between the Common block, the validation raises an exception.
PSyclone SymbolTable error: There is a name clash for symbol 'zeta' that cannot be resolved by renaming one of the instances because:
E - PSyclone SymbolTable error: Cannot rename symbol 'zeta' because it has a CommonBlock interface.
E - PSyclone SymbolTable error: Cannot rename symbol 'zeta' because it has a CommonBlock interface.
## code examples
### Common Block
```python
simple_code_with_common_clash = """subroutine caller()
integer :: istr
integer :: iend
integer :: i
real, dimension(10) :: zeta
common /ocean/ zeta
istr = 0
iend = 4
do i = istr, iend, 1
zeta(i) = i
enddo
istr = 4
iend = 8
call foo(istr, iend)
end subroutine caller
subroutine foo(istr, iend)
integer :: istr
integer :: iend
integer :: i
real, dimension(10) :: zeta
common /ocean/ zeta
do i = istr, iend, 1
zeta(i) = i + 1
enddo
end subroutine foo
"""
def test_simple_code_with_common_clash():
psyir = FortranReader().psyir_from_source(simple_code_with_common_clash)
call = psyir.walk(Call)[0]
inline_trans = InlineTrans()
inline_trans.apply(call)