public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "Joost.VandeVondele at mat dot ethz.ch" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/63311] New: [4.9/5 Regression] -O1 optimization introduces valgrind warning
Date: Fri, 19 Sep 2014 15:03:00 -0000	[thread overview]
Message-ID: <bug-63311-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 63311
           Summary: [4.9/5 Regression] -O1 optimization introduces
                    valgrind warning
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Joost.VandeVondele at mat dot ethz.ch

The following testcase yields a valgrind error when compiled with -O1 but not
at -O0. 4.8 is fine 4.9/trunk is not.

> gfortran -O1 -g bug.f90 && valgrind ./a.out 
==57092== Conditional jump or move depends on uninitialised value(s)
==57092==    at 0x4006F5: __m1_MOD_test (bug.f90:20)
==57092==    by 0x4007BB: main (bug.f90:36)
==57092== ERROR SUMMARY: 4 errors from 1 contexts (suppressed: 6 from 6)

> cat bug.f90
MODULE M1
  IMPLICIT NONE
CONTAINS
  INTEGER FUNCTION foo()
     INTEGER, VOLATILE :: v=42
     foo=v
  END FUNCTION
  SUBROUTINE test(n,flag)
    INTEGER :: n,i,j,k,l,tt
    LOGICAL :: flag
    REAL(KIND=8) :: v,t
    IF (flag) THEN
      t=42
      tt=foo()
    ENDIF
    v=0
    DO i=1,n
       v=0
       IF (flag) THEN
          IF (tt==i) v=MAX(v,t)
       ENDIF
       DO j=1,n
        DO k=1,n
            v=MAX(v,sin(REAL(j*k)))
         ENDDO
       ENDDO
    ENDDO
  END SUBROUTINE
END MODULE M1

USE M1
INTEGER :: n
LOGICAL :: flag
n=4
flag=.FALSE.
CALL test(n,flag)
END

what seems to happen is that '(tt==i)' is evaluated before IF (flag) is
evaluated, also in the case where 'flag==.FALSE.', while 'tt' is only
initialized in the .TRUE. case. 

I actually think generated code might nevertheless be correct, but it makes
valgrind less useful on -O1 code.


             reply	other threads:[~2014-09-19 15:03 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-19 15:03 Joost.VandeVondele at mat dot ethz.ch [this message]
2014-09-22 10:24 ` [Bug middle-end/63311] " rguenth at gcc dot gnu.org
2014-09-22 10:24 ` rguenth at gcc dot gnu.org
2014-09-22 10:34 ` dominiq at lps dot ens.fr
2014-10-09  9:45 ` jakub at gcc dot gnu.org
2014-10-30 10:42 ` jakub at gcc dot gnu.org
2014-10-31  9:30 ` Joost.VandeVondele at mat dot ethz.ch
2014-10-31  9:34 ` Joost.VandeVondele at mat dot ethz.ch
2014-11-24 13:27 ` rguenth at gcc dot gnu.org
2014-11-24 13:54 ` Joost.VandeVondele at mat dot ethz.ch
2015-06-26 20:12 ` [Bug middle-end/63311] [4.9/5/6 " jakub at gcc dot gnu.org
2015-06-26 20:36 ` jakub at gcc dot gnu.org
2021-05-14  9:47 ` [Bug middle-end/63311] [9/10/11/12 " jakub at gcc dot gnu.org
2021-06-01  8:06 ` rguenth at gcc dot gnu.org
2022-02-15 12:09 ` mark at gcc dot gnu.org
2022-02-16 22:49 ` dmalcolm at gcc dot gnu.org
2022-02-17  2:41 ` cvs-commit at gcc dot gnu.org
2022-05-27  9:35 ` [Bug middle-end/63311] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:31 ` jakub at gcc dot gnu.org
2023-07-07 10:30 ` [Bug middle-end/63311] [11/12/13/14 " rguenth at gcc dot gnu.org
2023-09-03  3:39 ` [Bug middle-end/63311] [11/12 " pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-63311-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).