no detection of undefined variable when passed through a module ?

no detection of undefined variable when passed through a module ?

Hi,

My present version of Intel compiler is 11.1.069

I join two examples where the undefined variable is detected on execution in one case but not in the other when this variable is passed via a fortan module.

The programs are below:
module mod_trigo
save
real*8 :: cx,c2x
real*8 :: sx,s2x,s3x
end module mod_trigo
!
program essai_c2x_undef1
use mod_trigo
implicit none
!
open(7,file='essai_c2x_undef_result',form='formatted',status='unknown')
sx=0.3d0 ; cx=dsqrt(1.d0-sx*sx)
call fonction
write(7,'(a,2(1pd16.6))') ' sx cx =',sx,cx
write(7,'(a,2(1pd16.6))') ' s2x c2x =',s2x,c2x
write(7,'(a,1pd16.6)') ' s3x = sx*c2x + s2x*cx = ',s3x
!
close(7)
end program essai_c2x_undef1
!
subroutine fonction
use mod_trigo
implicit none
s2x=2*sx*cx
! c2x=cx*cx - sx*sx ! <== definition of c2x
s3x=sx*c2x + s2x*cx
end subroutine fonction
!
!--------------------------------------------------------------
!compiled with Intel 11.1.069 :
! ifort -check all -watch all -O2 -o $1_go $1.f90
!result:
!sx cx = 3.000000D-01 9.539392D-01
!s2x c2x = 5.723635D-01 0.000000D+00
!s3x = sx*c2x + s2x*cx = 5.460000D-01
!--------------------------------------------------------------
!compiled with Intel-11.1.069
! ifort -check all -watch all -o $1_go $1.f90
!Result:
!sx cx = 3.000000D-01 9.539392D-01
!s2x c2x = 5.723635D-01 0.000000D+00
!s3x = sx*c2x + s2x*cx = 5.460000D-01
!--------------------------------------------------------------

program essai_c2x_undef2
implicit none
!
real*8 :: cx,c2x,sx,s2x,s3x
!
open(7,file='essai_c2x_undef_result',form='formatted',status='unknown')
sx=0.3d0 ; cx=dsqrt(1.d0-sx*sx)
s2x=2*sx*cx
! c2x=cx*cx - sx*sx ! <== definition of c2x
s3x=sx*c2x + s2x*cx
!
write(7,'(a,2(1pd16.6))') ' sx cx =',sx,cx
write(7,'(a,2(1pd16.6))') ' s2x c2x =',s2x,c2x
write(7,'(a,1pd16.6)') ' s3x = sx*c2x + s2x*cx = ',s3x
!
close(7)
end program essai_c2x_undef2
!---------------------------------------------------------
! after compilation with Intel-11.1.069 (with or without O2) :
!
!==> a warning diagnosis is issued on execution unlike le case where c2x was passed to the subroutine through a module
!
! result :
!
!forrtl: severe (193): Run-Time Check Failure. The variable 'essai_c2x_undef_$C2X' is being used without being defined
!Image PC Routine Line Source
!essai_c2x_undef2_ 0808E42D Unknown Unknown Unknown
!essai_c2x_undef2_ 0808D225 Unknown Unknown Unknown
!essai_c2x_undef2_ 0806154F Unknown Unknown Unknown
!essai_c2x_undef2_ 0804BE47 Unknown Unknown Unknown
!essai_c2x_undef2_ 0804C582 Unknown Unknown Unknown
!essai_c2x_undef2_ 08049D54 Unknown Unknown Unknown
!essai_c2x_undef2_ 08049C81 Unknown Unknown Unknown
!libc.so.6 4005B450 Unknown Unknown Unknown
!essai_c2x_undef2_ 08049BC1 Unknown Unknown Unknown
!-----------------------------------------------------------------

Is there a flaw anywhere ?

Sincerely Yours

JL Bocquet

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I believe you're correct in pointing out that ifort has difficulty diagnosing undefined module variables (undefined in the Fortran terminology, referred to elsewhere as uninitialized). The save which you set explicitly in the module is probably the default; this may contribute to the difficulty of diagnosing defined status. If this problem is in fact typical of module variables, it's a problem which the proponents of modules like to ignore.
I get similar results to yours with the current Windows X64 version of ifort.

This thread would be more appropriate on one of the Fortran forum sections.
The following would be more appropriate on Inspector forum:
I got a fresh copy of Windows Inspector (which ought to support Fortran now). I was unable to persuade it to import the inspector file created by ifort /Qdiag-enable:sc.
Running inspector on your example compiled without debug information showed uninitialized data at the assembler view level. When compiled with debug information, it reported no problems.

Leave a Comment

Please sign in to add a comment. Not a member? Join today