From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22926 invoked by alias); 19 Sep 2014 15:03:48 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 22873 invoked by uid 48); 19 Sep 2014 15:03:40 -0000 From: "Joost.VandeVondele at mat dot ethz.ch" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 5.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: Joost.VandeVondele at mat dot ethz.ch X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-09/txt/msg01957.txt.bz2 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.