This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/31447] set intent(out) arguments to uninitialized



------- Comment #3 from jv244 at cam dot ac dot uk  2009-09-19 11:37 -------
I've also run into this issue, it would be great if there would be a flag like
-finit-undefined-intentout (?), so that intent(out) variable would first be
undefined by the compiler (in a way that valgrind notices this with memcheck).
This is easy to do on the source level (see below), so I would hope this is
possible as well in the FE. The example would be:

MODULE test

CONTAINS
 SUBROUTINE S1(a)
  INTEGER, DIMENSION(:,:), INTENT(OUT) :: a

  ! FE generated code
  INTEGER :: uninitialized_a_type_dummy

a=RESHAPE((/(TRANSFER(uninitialized_a_type_dummy,uninitialized_a_type_dummy),i=1,SIZE(a))/),SHAPE(a))

  ! rest of the procedure

 END SUBROUTINE
END MODULE test

USE test
  INTEGER :: a(3,3)
  a=0
  CALL S1(a)
  write(6,*) a
  IF(ANY(a.NE.0)) WRITE(6,*) "No problem"
END

In this way, valgrind does produce a warning when a is being written after the
call to S1. The above example works also for derived types with default
initializers and similar.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31447


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]