https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83344

            Bug ID: 83344
           Summary: Use of uninitialized memory with ASSOCIATE and strings
           Product: gcc
           Version: 6.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jb at gcc dot gnu.org
  Target Milestone: ---

Consider the testcase

subroutine foo()

  implicit none

  character(len=4) :: s
  s = "a"

  associate(w => trim(s))
  end associate

end subroutine foo

Compiling with "gfortran -c -fdump-tree-original" and looking at the
003t.original dump, one can see that the length of the character variable w
varies randomly from one compilation to the next. Suggestion that it's reading
uninitialized memory. valgrind doesn't find anything fishy, though, maybe due
to extensive use of unions etc. in the frontend.

Per se, the 's = "a"' statement isn't necessary, it's just there to prevent
trim(s) from being non-standards compliant.

Removing the trim() call, that is, associating w=>s directly makes this issue
fo away. So the error is somehow in how the return value of trim(), simplified
at compile time, is assigned to the length of w.

Tested with version 6.3 and trunk on x86_64, and trunk on
powerpc64-unknown-linux-gnu.

Reply via email to