Bug 43796 - [4.5 Regression] ICE in is_overflow_infinity (tree-vrp.c:184) with gfortran -fcheck=bounds -O2
Summary: [4.5 Regression] ICE in is_overflow_infinity (tree-vrp.c:184) with gfortran -...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.5.1
Assignee: Richard Biener
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2010-04-19 10:11 UTC by Mat Cross
Modified: 2010-04-20 09:05 UTC (History)
2 users (show)

See Also:
Host:
Target: i386-unknown-linux-gnu
Build:
Known to work: 4.4.4 4.6.0
Known to fail: 4.5.0
Last reconfirmed: 2010-04-19 12:26:31


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mat Cross 2010-04-19 10:11:20 UTC
> uname -a
Linux loanamd25 2.6.16.46-0.10-smp #1 SMP Mon May 7 13:37:05 UTC 2007 x86_64 x86_64 x86_64 GNU/Linux

> gfortran --version
GNU Fortran (GCC) 4.5.0

> cat f06fkfn.f90
    FUNCTION F06FKFN(N,W,INCW,X,INCX)
       IMPLICIT NONE
       INTEGER, PARAMETER :: WP = KIND(0.0D0)
       REAL (KIND=WP)                  :: F06FKFN
       REAL (KIND=WP), PARAMETER       :: ONE = 1.0E+0_WP
       REAL (KIND=WP), PARAMETER       :: ZERO = 0.0E+0_WP
       INTEGER, INTENT (IN)            :: INCW, INCX, N
       REAL (KIND=WP), INTENT (IN)     :: W(*), X(*)
       REAL (KIND=WP)                  :: ABSYI, NORM, SCALE, SSQ
       INTEGER                         :: I, IW, IX
       REAL (KIND=WP), EXTERNAL        :: F06BMFN
       INTRINSIC                          ABS, SQRT
       IF (N<1) THEN
          NORM = ZERO
       ELSE IF (N==1) THEN
          NORM = SQRT(W(1))*ABS(X(1))
       ELSE
          IF (INCW>0) THEN
             IW = 1
          ELSE
             IW = 1 - (N-1)*INCW
          END IF
          IF (INCX>0) THEN
             IX = 1
          ELSE
             IX = 1 - (N-1)*INCX
          END IF
          SCALE = ZERO
          SSQ = ONE
          DO I = 1, N
             IF ((W(IW)/=ZERO) .AND. (X(IX)/=ZERO)) THEN
                ABSYI = SQRT(W(IW))*ABS(X(IX))
                IF (SCALE<ABSYI) THEN
                   SSQ = 1 + SSQ*(SCALE/ABSYI)**2
                   SCALE = ABSYI
                ELSE
                   SSQ = SSQ + (ABSYI/SCALE)**2
                END IF
             END IF
             IW = IW + INCW
             IX = IX + INCX
          END DO
          NORM = F06BMFN(SCALE,SSQ)
       END IF
       F06FKFN = NORM
       RETURN
    END FUNCTION F06FKFN

> gfortran -O3 -m32 -fcheck=all -c f06fkfn.f90
f06fkfn.f90: In function ‘f06fkfn’:
f06fkfn.f90:1:0: internal compiler error: Segmentation fault
Comment 1 Dominique d'Humieres 2010-04-19 10:56:26 UTC
Confirmed on trunk with '-O[23] -m32 -fcheck=bounds' (compiles with '-O[01s]'). Works for me with 4.5 revision 157991 and 4.4.2 (with '-fbounds-check' instead of '-fcheck=bounds'), hence at least a 4.6 regression.
Comment 2 Tobias Burnus 2010-04-19 11:39:56 UTC
Confirm. It fails with 4.5 and 4.6 using the option -fbounds-check (== -fcheck-bounds), but only with -O2 and higher and for some reasons only with -m32 and not with -m64 on x86_64-unknown-linux-gnu.

It works with GCC 4.1/4.2/4.3/4.4.

Valgrind shows:

==2634== Invalid read of size 2
==2634==    at 0x9643CA: is_overflow_infinity (tree-vrp.c:184)
==2634==    by 0x96447D: usable_range_p (tree-vrp.c:797)
==2634==    by 0x96A3DD: compare_ranges (tree-vrp.c:3388)
==2634==    by 0x96B083: vrp_evaluate_conditional_warnv_with_ops (tree-vrp.c:5669)
==2634==    by 0x96B91F: vrp_evaluate_conditional (tree-vrp.c:5710)
==2634==    by 0x9309DE: thread_across_edge (tree-ssa-threadedge.c:537)
==2634==    by 0x9765ED: execute_vrp (tree-vrp.c:7214)
==2634==    by 0x785B9A: execute_one_pass (passes.c:1569)
==2634==    by 0x785E24: execute_pass_list (passes.c:1624)
==2634==    by 0x785E36: execute_pass_list (passes.c:1625)
==2634==    by 0x87AB34: tree_rest_of_compilation (tree-optimize.c:413)
==2634==    by 0x9FCA60: cgraph_expand_function (cgraphunit.c:1548)
==2634==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==2634==
test.f90: In function 'f06fkfn':
test.f90:1:0: internal compiler error: Segmentation fault
Please submit a full bug report,
Comment 3 Richard Biener 2010-04-19 12:26:31 UTC
Program received signal SIGSEGV, Segmentation fault.
0x0000000000bdb380 in needs_overflow_infinity (type=0x0)
    at /space/rguenther/src/svn/gcc-4_5-branch/gcc/tree-vrp.c:184
184       return INTEGRAL_TYPE_P (type) && !TYPE_OVERFLOW_WRAPS (type);
(gdb) up
#1  0x0000000000bdb434 in is_overflow_infinity (val=0x7ffff5adfe70)
    at /space/rguenther/src/svn/gcc-4_5-branch/gcc/tree-vrp.c:269
269       return (needs_overflow_infinity (TREE_TYPE (val))
(gdb) call debug_tree (val)
 <ssa_name 0x7ffff5adfe70 nothrow var <var_decl 0x7ffff7fbf0a0 i>def_stmt 

    version 56 in-free-list>

Confirmed.

We free the SSA name in substitute_and_fold () but it is still used in
symbolical ranges which we end up using by jump threading.

If we do so we shouldn't DCE stmts in substitute_and_fold ().

There's also a missed-optimization which if fixed fixes this PR as well.
Comment 4 Richard Biener 2010-04-19 15:17:49 UTC
Subject: Bug 43796

Author: rguenth
Date: Mon Apr 19 15:17:26 2010
New Revision: 158520

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=158520
Log:
2010-04-19  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/43796
	* tree-vrp.c (adjust_range_with_scev): Lookup init and step
	from SCEV in the lattice.
	(vrp_visit_phi_node): Dump change.

	* gfortran.dg/pr43796.f90: New testcase.

Added:
    trunk/gcc/testsuite/gfortran.dg/pr43796.f90
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-vrp.c

Comment 5 Richard Biener 2010-04-20 09:04:20 UTC
Subject: Bug 43796

Author: rguenth
Date: Tue Apr 20 09:04:05 2010
New Revision: 158548

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=158548
Log:
2010-04-20  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/43796
	* tree-vrp.c (adjust_range_with_scev): Lookup init and step
	from SCEV in the lattice.
	(vrp_visit_phi_node): Dump change.

	* gfortran.dg/pr43796.f90: New testcase.

Added:
    branches/gcc-4_5-branch/gcc/testsuite/gfortran.dg/pr43796.f90
Modified:
    branches/gcc-4_5-branch/gcc/ChangeLog
    branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_5-branch/gcc/tree-vrp.c

Comment 6 Richard Biener 2010-04-20 09:05:46 UTC
Fixed.