Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29230 Discussions

ifx does not respect global values passed by reference

foxtran
New Contributor II
3,901 Views

Assuming, that one has the following code:

main.f90:

program main
  implicit none
  common /mem/ imem
  integer :: imem
  imem = 0
  call test(imem)
end program main

subroutine update_imem
  implicit none
  common /mem/ imem
  integer :: imem
  imem = 30
end subroutine update_imem

 test.f90:

subroutine test(imem)
  integer :: imem
  print *, imem
  call update_imem()
  print *, imem
end subroutine test


Compilation:

ifx test.f90 main.f90 -O0 -o a.exe



Running gives the output:

0
30



that is expected.

However, if it will be compiled with -O3:

ifx test.f90 main.f90 -O0 -o a.exe


the output will be 

0
0


The expected output should be the same as without optimisations. This behaviour is for NAG/ArmFlang/gfortran/LLVMFlang/AOCC/ifort compilers, but not for ifx.

@Ron_Green ,  could you please have a look?

Related issues:
https://community.intel.com/t5/Intel-Fortran-Compiler/pointer-to-procedure-is-constant-while-should-not/m-p/1634195
https://community.intel.com/t5/Intel-Fortran-Compiler/common-variable-passed-as-argument-of-function-is-overoptimized/m-p/1573128 



0 Kudos
1 Solution
Steve_Lionel
Honored Contributor III
3,857 Views

This is an invalid program. It violates:

Steve_Lionel_0-1752611655779.png

 

In other words, you're aliasing the dummy argument and the COMMON variable, and that is not allowed here. 

View solution in original post

4 Replies
Steve_Lionel
Honored Contributor III
3,858 Views

This is an invalid program. It violates:

Steve_Lionel_0-1752611655779.png

 

In other words, you're aliasing the dummy argument and the COMMON variable, and that is not allowed here. 

foxtran
New Contributor II
3,838 Views

@Steve_Lionel, thank you so much. It was a bit hard for me to understand those sentences with "unless". 

So, it is time to update 40k LoC with this violation...

0 Kudos
Steve_Lionel
Honored Contributor III
3,819 Views

You can, for now, compile with /assume:dummy_aliases and I think it should do what you want. It is still invalid code.

All of the "unless" bullets are cases where you are allowed to make aliases - the TARGET attribute (implied by POINTER, which I think is relevant to your other thread), is one of these.

One of the core tenets of Fortran is that aliasing is generally disallowed, unless you tell the compiler explicitly that it can occur.

foxtran
New Contributor II
3,781 Views

@Steve_Lionel, thank you! With `-assume dummy_aliases`, all tests were passed. And thank you for explanation  about Fortran. 

0 Kudos
Reply