[Bug fortran/31120] ICE with integer_exponentiation_1.f90 and -ffast-math
--- Comment #9 from fxcoudert at gcc dot gnu dot org 2007-03-17 19:58 --- Subject: Bug 31120 Author: fxcoudert Date: Sat Mar 17 19:58:37 2007 New Revision: 123028 URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=123028 Log: PR fortran/31120 * trans-expr.c (gfc_conv_powi): Make n argument unsigned hwi. (gfc_conv_cst_int_power): Handle integer exponent with care, since it might be too large for us. * gfortran.dg/integer_exponentiation_2.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/integer_exponentiation_2.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/trans-expr.c trunk/gcc/testsuite/ChangeLog -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31120
[Bug fortran/31120] ICE with integer_exponentiation_1.f90 and -ffast-math
--- Comment #7 from dominiq at lps dot ens dot fr 2007-03-15 08:24 --- And Dominique, I would appreciate if you could test the patch on ppc-darwin7. So far all the tests passed. I am doing a full regtesting of gfortran, but I do not expect any new failure. Thanks for the fix. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31120
[Bug fortran/31120] ICE with integer_exponentiation_1.f90 and -ffast-math
--- Comment #8 from dominiq at lps dot ens dot fr 2007-03-15 08:52 --- regtest results: ... Running /Users/dominiq/test/gcc-4.3-20070309/gcc/testsuite/gfortran.dg/dg.exp ... FAIL: gfortran.dg/large_real_kind_2.F90 -O0 execution test ... FAIL: gfortran.dg/large_real_kind_2.F90 -Os execution test FAIL: gfortran.dg/large_real_kind_form_io_2.f90 -O0 execution test ... FAIL: gfortran.dg/large_real_kind_form_io_2.f90 -Os execution test FAIL: gfortran.dg/secnds-1.f -Os execution test Running /Users/dominiq/test/gcc-4.3-20070309/gcc/testsuite/gfortran.dg/gomp/gomp.exp ... ... === gfortran Summary === # of expected passes16445 # of unexpected failures17 # of expected failures 7 # of unsupported tests 58 /sw/lib/gcc4/bin/gfortran version 4.3.0 20070309 (experimental) -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31120
[Bug fortran/31120] ICE with integer_exponentiation_1.f90 and -ffast-math
--- Comment #3 from fxcoudert at gcc dot gnu dot org 2007-03-14 12:31 --- Here's a patch that should make the code in gfc_conv_cst_int_power() work in all cases: Index: trans-expr.c === --- trans-expr.c(revision 122912) +++ trans-expr.c(working copy) @@ -634,7 +634,7 @@ /* Recursive function to expand the power operator. The temporary values are put in tmpvar. The function returns tmpvar[1] ** n. */ static tree -gfc_conv_powi (gfc_se * se, int n, tree * tmpvar) +gfc_conv_powi (gfc_se * se, unsigned HOST_WIDE_INT n, tree * tmpvar) { tree op0; tree op1; @@ -681,15 +681,25 @@ tree tmp; tree type; tree vartmp[POWI_TABLE_SIZE]; - int n; + HOST_WIDE_INT m; + unsigned HOST_WIDE_INT n; int sgn; + /* If exponent is too large, we won't expand it anyway, so don't bother + with large integer values. */ + if (!double_int_fits_in_shwi_p (TREE_INT_CST (rhs))) +return 0; + + m = double_int_to_shwi (TREE_INT_CST (rhs)); + /* There's no ABS for HOST_WIDE_INT, so here we go. It also takes care + of the asymmetric range of the integer type. */ + n = (unsigned HOST_WIDE_INT) (m 0 ? -m : m); + type = TREE_TYPE (lhs); - n = abs (TREE_INT_CST_LOW (rhs)); sgn = tree_int_cst_sgn (rhs); - if (((FLOAT_TYPE_P (type) !flag_unsafe_math_optimizations) || optimize_siz e) - (n 2 || n -1)) + if (((FLOAT_TYPE_P (type) !flag_unsafe_math_optimizations) + || optimize_size) (m 2 || m -1)) return 0; /* rhs == 0 */ @@ -698,6 +708,7 @@ se-expr = gfc_build_const (type, integer_one_node); return 1; } + /* If rhs 0 and lhs is an integer, the result is -1, 0 or 1. */ if ((sgn == -1) (TREE_CODE (type) == INTEGER_TYPE)) { It's regtesting right now. The following should now be done: * write a testcase, using both kind=4 and 8 integers as exponents, and testing difficult cases (huge(),-huge(),-huge()-1, etc.); the testcase should also check constant vs. non-constant results, to make sure the testcase run isn't rendered useless by constant folding * the code generated should be manually checked in the above-mentionned difficult cases (huge(), -huge(), ...) If nobody does it before the week-end, I'll do it then (but won't have time before that). And Dominique, I would appreciate if you could test the patch on ppc-darwin7. -- fxcoudert at gcc dot gnu dot org changed: What|Removed |Added AssignedTo|unassigned at gcc dot gnu |fxcoudert at gcc dot gnu dot |dot org |org Status|NEW |ASSIGNED Keywords||patch Last reconfirmed|2007-03-10 12:15:25 |2007-03-14 12:31:35 date|| http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31120
[Bug fortran/31120] ICE with integer_exponentiation_1.f90 and -ffast-math
--- Comment #4 from dominiq at lps dot ens dot fr 2007-03-14 13:58 --- Subject: Re: ICE with integer_exponentiation_1.f90 and -ffast-math And Dominique, I would appreciate if you could test the patch on ppc-darwin7. I'll do it tonight, but before could you test the following code: integer(4) :: i integer(8) :: j real(4) :: a real(8) :: b, c, d a = 1.0 + epsilon(a) b = 1.0 + epsilon(b) print *, a**huge(i), a**(-huge(i)), a**(-huge(i)-1) print '(3(1PG30.17))', b**huge(i), b**(-huge(i)), b**(-huge(i)-1) c = b**huge(i) d= b**(-huge(i)) print '(3(1PG30.17))', c*d, d/b, exp(-huge(i)*log(b)) d=1/b do i = 1, 31 d = d*d end do print '(2(1PG30.17))', d, b*d !print *, b**huge(j), b**(-huge(j)), b**(-huge(j)-1) end If I uncomment the last print, I get: [karma] f90/bug% gfc test_pow.f90 Out of stack space. Try running 'limit stacksize unlimited' in the shell to raise its limit. Is this also fixed by your patch? -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31120
[Bug fortran/31120] ICE with integer_exponentiation_1.f90 and -ffast-math
--- Comment #5 from fxcoudert at gcc dot gnu dot org 2007-03-14 14:02 --- (In reply to comment #4) I'll do it tonight, but before could you test the following code [karma] f90/bug% gfc test_pow.f90 Out of stack space. Try running 'limit stacksize unlimited' in the shell to raise its limit. On i686-linux, the unpatched compiler works OK without -ffast-math and segfaults with it. With the patch, it runs fine in both cases. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31120
[Bug fortran/31120] ICE with integer_exponentiation_1.f90 and -ffast-math
--- Comment #6 from dominiq at lps dot ens dot fr 2007-03-14 14:27 --- Subject: Re: ICE with integer_exponentiation_1.f90 and -ffast-math On i686-linux, the unpatched compiler works OK without -ffast-math and segfaults with it. I am a little bit worried about that. As far as I know the stack size on OSX is limited to 65536 kbytes (at least I don't know how to increase it further under 10.3). Could you test the code with the last print uncommented and the stack size limited to 65536 kbytes? TIA -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31120
[Bug fortran/31120] ICE with integer_exponentiation_1.f90 and -ffast-math
--- Comment #1 from dominiq at lps dot ens dot fr 2007-03-10 10:25 --- FX Coudert reported that compiling the following code real :: a, b a = 3.0 b = a**(-4294967296_8) print *, b end segfaults on i686-linux (without -ffast-math). On OSX 10.3.9 I get Out of stack space. Try running 'limit stacksize unlimited' in the shell to raise its limit. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31120
[Bug fortran/31120] ICE with integer_exponentiation_1.f90 and -ffast-math
-- burnus at gcc dot gnu dot org changed: What|Removed |Added CC||burnus at gcc dot gnu dot ||org Status|UNCONFIRMED |NEW Ever Confirmed|0 |1 GCC target triplet|powerpc-apple-darwin7 | Keywords||ice-on-valid-code Last reconfirmed|-00-00 00:00:00 |2007-03-10 12:15:25 date|| http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31120
[Bug fortran/31120] ICE with integer_exponentiation_1.f90 and -ffast-math
--- Comment #2 from tkoenig at gcc dot gnu dot org 2007-03-10 12:33 --- (In reply to comment #1) FX Coudert reported that compiling the following code real :: a, b a = 3.0 b = a**(-4294967296_8) print *, b end segfaults on i686-linux (without -ffast-math). This is closely related to PR 30834. -- tkoenig at gcc dot gnu dot org changed: What|Removed |Added CC||tkoenig at gcc dot gnu dot ||org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31120