public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/98904] New: valgrind error in gfc_trans_assignment_1 during bootstrap
@ 2021-01-31 16:44 dcb314 at hotmail dot com
  2021-01-31 16:52 ` [Bug fortran/98904] " dcb314 at hotmail dot com
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: dcb314 at hotmail dot com @ 2021-01-31 16:44 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98904
           Summary: valgrind error in gfc_trans_assignment_1 during
                    bootstrap
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dcb314 at hotmail dot com
  Target Milestone: ---

I just tried to make a valgrind build of gcc fortran with -O3.

My configure lines are

../trunk.git/configure --prefix=/home/dcb/gcc/$PREFIX \
        --disable-bootstrap \
        --disable-multilib \
        --disable-werror \
        --with-pkgversion=$HASH \
        --enable-checking=valgrind \
        --enable-languages=fortran

sed 's/-O2/-O3/' < Makefile > Makefile.tmp
mv Makefile.tmp Makefile

When compiling source code file omp_lib.f90 in libssp, I get

==147960== Conditional jump or move depends on uninitialised value(s)
==147960==    at 0x761595: gfc_trans_assignment_1(gfc_expr*, gfc_expr*, bool,
bool, bool, bool) (trans-expr.c:11340)
==147960==    by 0x75FE1C: gfc_trans_assignment(gfc_expr*, gfc_expr*, bool,
bool, bool, bool) (trans-expr.c:11557)
==147960==    by 0x71D39A: trans_code(gfc_code*, tree_node*) (trans.c:1922)
==147960==    by 0x745B96: gfc_generate_function_code(gfc_namespace*)
(trans-decl.c:6880)

Line 11340 is

     && lhs_caf_attr.codimension && rhs_caf_attr.codimension

As part of

  else if (flag_coarray == GFC_FCOARRAY_LIB
           && lhs_caf_attr.codimension && rhs_caf_attr.codimension
           && ((lhs_caf_attr.allocatable && lhs_refs_comp)
               || (rhs_caf_attr.allocatable && rhs_refs_comp)))
    {

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/98904] valgrind error in gfc_trans_assignment_1 during bootstrap
  2021-01-31 16:44 [Bug fortran/98904] New: valgrind error in gfc_trans_assignment_1 during bootstrap dcb314 at hotmail dot com
@ 2021-01-31 16:52 ` dcb314 at hotmail dot com
  2021-01-31 21:38 ` dcb314 at hotmail dot com
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: dcb314 at hotmail dot com @ 2021-01-31 16:52 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from David Binderman <dcb314 at hotmail dot com> ---
The compile line of relevance is

/home/dcb/gcc/working.valgrind/./gcc/gfortran
-B/home/dcb/gcc/working.valgrind/./gcc/
-B/home/dcb/gcc/results.20210131.valgrind/x86_64-pc-linux-gnu/bin/
-B/home/dcb/gcc/results.20210131.valgrind/x86_64-pc-linux-gnu/lib/ -isystem
/home/dcb/gcc/results.20210131.valgrind/x86_64-pc-linux-gnu/include -isystem
/home/dcb/gcc/results.20210131.valgrind/x86_64-pc-linux-gnu/sys-include    -L.
-Wall -L../libgfortran -fcf-protection -mshstk -cpp -fopenmp -fsyntax-only
omp_lib.f90

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/98904] valgrind error in gfc_trans_assignment_1 during bootstrap
  2021-01-31 16:44 [Bug fortran/98904] New: valgrind error in gfc_trans_assignment_1 during bootstrap dcb314 at hotmail dot com
  2021-01-31 16:52 ` [Bug fortran/98904] " dcb314 at hotmail dot com
@ 2021-01-31 21:38 ` dcb314 at hotmail dot com
  2021-02-01  8:54 ` marxin at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: dcb314 at hotmail dot com @ 2021-01-31 21:38 UTC (permalink / raw)
  To: gcc-bugs

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

David Binderman <dcb314 at hotmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vehre at gcc dot gnu.org

--- Comment #2 from David Binderman <dcb314 at hotmail dot com> ---
git blame says

574284e9c496 (Andre Vehreschild          2016-10-22 14:33:38 +0200 11339)  
else if (flag_coarray == GFC_FCOARRAY_LIB
574284e9c496 (Andre Vehreschild          2016-10-22 14:33:38 +0200 11340)      
   && lhs_caf_attr.codimension && rhs_caf_attr.codimension
8c92e4522ddd (Andre Vehreschild          2016-12-14 13:49:45 +0100 11341)      
   && ((lhs_caf_attr.allocatable && lhs_refs_comp)
8c92e4522ddd (Andre Vehreschild          2016-12-14 13:49:45 +0100 11342)      
       || (rhs_caf_attr.allocatable && rhs_refs_comp)))
3c9f5092c6d3 (Andre Vehreschild          2016-09-19 15:45:40 +0200 11343)     {

Perhaps Andre can offer an opinion.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/98904] valgrind error in gfc_trans_assignment_1 during bootstrap
  2021-01-31 16:44 [Bug fortran/98904] New: valgrind error in gfc_trans_assignment_1 during bootstrap dcb314 at hotmail dot com
  2021-01-31 16:52 ` [Bug fortran/98904] " dcb314 at hotmail dot com
  2021-01-31 21:38 ` dcb314 at hotmail dot com
@ 2021-02-01  8:54 ` marxin at gcc dot gnu.org
  2021-02-01  9:06 ` burnus at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-02-01  8:54 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
                 CC|                            |marxin at gcc dot gnu.org
   Last reconfirmed|                            |2021-02-01
     Ever confirmed|0                           |1

--- Comment #3 from Martin Liška <marxin at gcc dot gnu.org> ---
I've just tried running that with UBSAN+ASAN instrumented compiler and it seems
fine.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/98904] valgrind error in gfc_trans_assignment_1 during bootstrap
  2021-01-31 16:44 [Bug fortran/98904] New: valgrind error in gfc_trans_assignment_1 during bootstrap dcb314 at hotmail dot com
                   ` (2 preceding siblings ...)
  2021-02-01  8:54 ` marxin at gcc dot gnu.org
@ 2021-02-01  9:06 ` burnus at gcc dot gnu.org
  2021-02-01  9:14 ` dcb314 at hotmail dot com
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: burnus at gcc dot gnu.org @ 2021-02-01  9:06 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org

--- Comment #4 from Tobias Burnus <burnus at gcc dot gnu.org> ---
The code has:

 ... lhs_refs_comp = false, rhs_refs_comp = false
...
  if (flag_coarray == GFC_FCOARRAY_LIB)
    {
      lhs_caf_attr = gfc_caf_attr (expr1, false, &lhs_refs_comp);
      rhs_caf_attr = gfc_caf_attr (expr2, false, &rhs_refs_comp);
    }
...

And the error "Conditional jump or move depends on uninitialised value(s)"
points, as you wrote, to the second line of

  else if (flag_coarray == GFC_FCOARRAY_LIB
           && lhs_caf_attr.codimension && rhs_caf_attr.codimension
           && ((lhs_caf_attr.allocatable && lhs_refs_comp)
               || (rhs_caf_attr.allocatable && rhs_refs_comp)))

However, the code looks perfectly fine to me.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/98904] valgrind error in gfc_trans_assignment_1 during bootstrap
  2021-01-31 16:44 [Bug fortran/98904] New: valgrind error in gfc_trans_assignment_1 during bootstrap dcb314 at hotmail dot com
                   ` (3 preceding siblings ...)
  2021-02-01  9:06 ` burnus at gcc dot gnu.org
@ 2021-02-01  9:14 ` dcb314 at hotmail dot com
  2021-02-01  9:26 ` marxin at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: dcb314 at hotmail dot com @ 2021-02-01  9:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from David Binderman <dcb314 at hotmail dot com> ---
Another test case. I compiled source code file dcabs1.f, from the lapack
package.

I got

$ /home/dcb/gcc/results.20210131.valgrind/bin/gfortran dcabs1.f
==76833== Conditional jump or move depends on uninitialised value(s)
==76833==    at 0x761595: gfc_trans_assignment_1(gfc_expr*, gfc_expr*, bool,
bool, bool, bool) (trans-expr.c:11340)
==76833==    by 0x75FE1C: gfc_trans_assignment(gfc_expr*, gfc_expr*, bool,
bool, bool, bool) (trans-expr.c:11557)
==76833==    by 0x71D39A: trans_code(gfc_code*, tree_node*) (trans.c:1922)
==76833==    by 0x745B96: gfc_generate_function_code(gfc_namespace*)
(trans-decl.c:6880)

Version of lapack is lapack-3.9.0. Note no optimiser.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/98904] valgrind error in gfc_trans_assignment_1 during bootstrap
  2021-01-31 16:44 [Bug fortran/98904] New: valgrind error in gfc_trans_assignment_1 during bootstrap dcb314 at hotmail dot com
                   ` (4 preceding siblings ...)
  2021-02-01  9:14 ` dcb314 at hotmail dot com
@ 2021-02-01  9:26 ` marxin at gcc dot gnu.org
  2021-02-01 10:25 ` dcb314 at hotmail dot com
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-02-01  9:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Martin Liška <marxin at gcc dot gnu.org> ---
(In reply to David Binderman from comment #5)
> Another test case. I compiled source code file dcabs1.f, from the lapack
> package.
> 
> I got
> 
> $ /home/dcb/gcc/results.20210131.valgrind/bin/gfortran dcabs1.f
> ==76833== Conditional jump or move depends on uninitialised value(s)
> ==76833==    at 0x761595: gfc_trans_assignment_1(gfc_expr*, gfc_expr*, bool,
> bool, bool, bool) (trans-expr.c:11340)
> ==76833==    by 0x75FE1C: gfc_trans_assignment(gfc_expr*, gfc_expr*, bool,
> bool, bool, bool) (trans-expr.c:11557)
> ==76833==    by 0x71D39A: trans_code(gfc_code*, tree_node*) (trans.c:1922)
> ==76833==    by 0x745B96: gfc_generate_function_code(gfc_namespace*)
> (trans-decl.c:6880)
> 
> Version of lapack is lapack-3.9.0. Note no optimiser.

Can you please point to the source file.

And can you please use the following valgrind option:
--expensive-definedness-checks=yes ?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/98904] valgrind error in gfc_trans_assignment_1 during bootstrap
  2021-01-31 16:44 [Bug fortran/98904] New: valgrind error in gfc_trans_assignment_1 during bootstrap dcb314 at hotmail dot com
                   ` (5 preceding siblings ...)
  2021-02-01  9:26 ` marxin at gcc dot gnu.org
@ 2021-02-01 10:25 ` dcb314 at hotmail dot com
  2021-02-01 10:26 ` dcb314 at hotmail dot com
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: dcb314 at hotmail dot com @ 2021-02-01 10:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from David Binderman <dcb314 at hotmail dot com> ---
Created attachment 50103
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50103&action=edit
fortran source code

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/98904] valgrind error in gfc_trans_assignment_1 during bootstrap
  2021-01-31 16:44 [Bug fortran/98904] New: valgrind error in gfc_trans_assignment_1 during bootstrap dcb314 at hotmail dot com
                   ` (6 preceding siblings ...)
  2021-02-01 10:25 ` dcb314 at hotmail dot com
@ 2021-02-01 10:26 ` dcb314 at hotmail dot com
  2021-02-02  9:03 ` marxin at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: dcb314 at hotmail dot com @ 2021-02-01 10:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from David Binderman <dcb314 at hotmail dot com> ---
(In reply to Martin Liška from comment #6)
> Can you please point to the source file.

./BLAS/SRC/dcabs1.f

I have attached a copy anyway.

> And can you please use the following valgrind option:
> --expensive-definedness-checks=yes ?

Already on. It is in my ~.valgrindrc.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/98904] valgrind error in gfc_trans_assignment_1 during bootstrap
  2021-01-31 16:44 [Bug fortran/98904] New: valgrind error in gfc_trans_assignment_1 during bootstrap dcb314 at hotmail dot com
                   ` (7 preceding siblings ...)
  2021-02-01 10:26 ` dcb314 at hotmail dot com
@ 2021-02-02  9:03 ` marxin at gcc dot gnu.org
  2021-02-03 14:09 ` dcb314 at hotmail dot com
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-02-02  9:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Martin Liška <marxin at gcc dot gnu.org> ---
I must say the code looks fine to me as well.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/98904] valgrind error in gfc_trans_assignment_1 during bootstrap
  2021-01-31 16:44 [Bug fortran/98904] New: valgrind error in gfc_trans_assignment_1 during bootstrap dcb314 at hotmail dot com
                   ` (8 preceding siblings ...)
  2021-02-02  9:03 ` marxin at gcc dot gnu.org
@ 2021-02-03 14:09 ` dcb314 at hotmail dot com
  2021-02-03 14:56 ` burnus at gcc dot gnu.org
  2021-02-03 19:10 ` dcb314 at hotmail dot com
  11 siblings, 0 replies; 13+ messages in thread
From: dcb314 at hotmail dot com @ 2021-02-03 14:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from David Binderman <dcb314 at hotmail dot com> ---
I added the debug lines

  fprintf( stderr, "%d\n", flag_coarray);
  fprintf( stderr, "%d\n", lhs_caf_attr.codimension);
  fprintf( stderr, "%d\n", rhs_caf_attr.codimension);
  fprintf( stderr, "%d\n", lhs_caf_attr.allocatable);
  fprintf( stderr, "%d\n", lhs_refs_comp);
  fprintf( stderr, "%d\n", rhs_caf_attr.allocatable);
  fprintf( stderr, "%d\n", rhs_refs_comp);

around line 11320 of file trans-expr.c, recompiled and re-ran the test.

The output from stderr is 

==44799== Conditional jump or move depends on uninitialised value(s)
==44799==    at 0x525DE53: __vfprintf_internal (in /usr/lib64/libc-2.32.so)
==44799==    by 0x525EA6B: buffered_vfprintf (in /usr/lib64/libc-2.32.so)
==44799==    by 0x52491D9: fprintf (in /usr/lib64/libc-2.32.so)
==44799==    by 0xFE3B61: gfc_trans_assignment_1(gfc_expr*, gfc_expr*, bool,
bool, bool, bool) (trans-expr.c:11321)

Line 11321 is the second line of debug, so valgrind says
lhs_caf_attr.codimension is uninitialised.

I also got valgrind output for lines 11322, 11323 and 11325.

So it looks to me like the codimension fields and the allocatable
fields are not initialised in this case.

The next stage may be to find out where those fields are supposed
to be initialised and find out why they aren't getting done.

I have no familiarity with fortran or its compiler. Perhaps
someone would be kind enough to point me in the right direction ?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/98904] valgrind error in gfc_trans_assignment_1 during bootstrap
  2021-01-31 16:44 [Bug fortran/98904] New: valgrind error in gfc_trans_assignment_1 during bootstrap dcb314 at hotmail dot com
                   ` (9 preceding siblings ...)
  2021-02-03 14:09 ` dcb314 at hotmail dot com
@ 2021-02-03 14:56 ` burnus at gcc dot gnu.org
  2021-02-03 19:10 ` dcb314 at hotmail dot com
  11 siblings, 0 replies; 13+ messages in thread
From: burnus at gcc dot gnu.org @ 2021-02-03 14:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from Tobias Burnus <burnus at gcc dot gnu.org> ---
(In reply to David Binderman from comment #10)
> lhs_caf_attr.codimension is uninitialised.

It is clear that lhs_caf_attr is uninitialized
- if and only if flag_coarray != GFC_FCOARRAY_LIB

It might be that some code optimizes converts

  if (flag_coarray == GFC_FCOARRAY_LIB && lhs_caf_attr.codimension)

to

  if (flag_coarray == GFC_FCOARRAY_LIB & lhs_caf_attr.codimension)

to speed up – relying that lhs_caf_attr.codimension accesses valid memory
(which may be uninitialized). The replacement would work correctly anywhere
where accessing uninitialized memory works. As: if flag_coarray ==
GFC_FCOARRAY_LIB is 0, the value of lhs_caf_attr.codimension does not matter –
and if it is not 0, lhs_caf_attr.codimension is properly initialized.

It might be that the either the middle end of GCC does this optimization or
that valgrind does this internally.

In any case, the Fortran-compiler part is perfectly valid C/C++.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug fortran/98904] valgrind error in gfc_trans_assignment_1 during bootstrap
  2021-01-31 16:44 [Bug fortran/98904] New: valgrind error in gfc_trans_assignment_1 during bootstrap dcb314 at hotmail dot com
                   ` (10 preceding siblings ...)
  2021-02-03 14:56 ` burnus at gcc dot gnu.org
@ 2021-02-03 19:10 ` dcb314 at hotmail dot com
  11 siblings, 0 replies; 13+ messages in thread
From: dcb314 at hotmail dot com @ 2021-02-03 19:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #12 from David Binderman <dcb314 at hotmail dot com> ---
(In reply to Tobias Burnus from comment #11)
> It might be that some code optimizes converts

...

> It might be that the either the middle end of GCC does this optimization or
> that valgrind does this internally.

I don't understand very much of your reply, but if you can replace
your two mights with facts, that would be IMHO a step in the right direction.

I replaced my existing fprintf code with slightly better code
on the obvious conditional:

  if (flag_coarray == GFC_FCOARRAY_LIB)
  {
    fprintf( stderr, "flag_coarray %d\n", flag_coarray);
    fprintf( stderr, "lhs_caf_attr.codimension %d\n",
lhs_caf_attr.codimension);
    fprintf( stderr, "rhs_caf_attr.codimension %d\n",
rhs_caf_attr.codimension);
    fprintf( stderr, "lhs_caf_attr.allocatable %d\n",
lhs_caf_attr.allocatable);
    fprintf( stderr, "lhs_refs_comp %d\n", lhs_refs_comp);
    fprintf( stderr, "rhs_caf_attr.allocatable %d\n",
rhs_caf_attr.allocatable);
    fprintf( stderr, "rhs_refs_comp %d\n", rhs_refs_comp);
  }

and, surprisingly, the problem seems to have gone away.

Mind you, I did compile with -O2 this time, not -O3 as originally specified, 
so it looks like I get dodgy results if I build the fortran compiler with -O3. 
I will avoid this in future. Deeper minds might want to look into this problem
some more.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-02-03 19:10 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-31 16:44 [Bug fortran/98904] New: valgrind error in gfc_trans_assignment_1 during bootstrap dcb314 at hotmail dot com
2021-01-31 16:52 ` [Bug fortran/98904] " dcb314 at hotmail dot com
2021-01-31 21:38 ` dcb314 at hotmail dot com
2021-02-01  8:54 ` marxin at gcc dot gnu.org
2021-02-01  9:06 ` burnus at gcc dot gnu.org
2021-02-01  9:14 ` dcb314 at hotmail dot com
2021-02-01  9:26 ` marxin at gcc dot gnu.org
2021-02-01 10:25 ` dcb314 at hotmail dot com
2021-02-01 10:26 ` dcb314 at hotmail dot com
2021-02-02  9:03 ` marxin at gcc dot gnu.org
2021-02-03 14:09 ` dcb314 at hotmail dot com
2021-02-03 14:56 ` burnus at gcc dot gnu.org
2021-02-03 19:10 ` dcb314 at hotmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).