GEOS-ESM / ESMA_cmake

Custom CMake macros for the GEOS Earth System Model
Apache License 2.0
4 stars 9 forks source link

Update Intel Fortran Debugging Flags to be more verbose and strict #296

Closed mathomp4 closed 8 months ago

mathomp4 commented 1 year ago

@tclune found a case where something like this:

program test

   implicit none

   if (foo()) then
      write (*,*) 'True'
   else
      write (*,*) 'False'
   end if

   contains
      logical function foo()
         foo = -1
      end function foo
end program test

was not detected by Intel. We should never really allow a logical to be set to an integer. By default though:

$ ifort test.F90 && ./a.out
 True

If we turn on -stand:

$ ifort -stand f18 test.F90 && ./a.out
test.F90(13): warning #6192: Fortran 2018 does not allow this data type conversion.
         foo = -1
---------------^
 True

Better but only a warning. Let's turn that to an error:

$ ifort -stand f18 -diag-error=6192 test.F90 && ./a.out
test.F90(13): error #6192: Fortran 2018 does not allow this data type conversion.
         foo = -1
---------------^
compilation aborted for test.F90 (code 1)

There we go.