public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/31120]  New: ICE with integer_exponentiation_1.f90 and -ffast-math
@ 2007-03-10 10:22 dominiq at lps dot ens dot fr
  2007-03-10 10:25 ` [Bug fortran/31120] " dominiq at lps dot ens dot fr
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: dominiq at lps dot ens dot fr @ 2007-03-10 10:22 UTC (permalink / raw)
  To: gcc-bugs

With gfortran 4.3.0 20070309 (powerpc-apple-darwin7) compiling
integer_exponentiation_1.f90 with -ffast-math gives an ICE with:

[address=806b1964 pc=00087bfc]
integer_exponentiation_1.f90: In function 'MAIN__':
integer_exponentiation_1.f90:4: internal compiler error: Segmentation Fault

This has been confirmed by Thomas Koenig and FX Coudert, see:

http://gcc.gnu.org/ml/fortran/2007-03/msg00203.html
http://gcc.gnu.org/ml/fortran/2007-03/msg00204.html

for additional information and problems.


-- 
           Summary: ICE with integer_exponentiation_1.f90 and -ffast-math
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dominiq at lps dot ens dot fr
GCC target triplet: powerpc-apple-darwin7


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31120


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

* [Bug fortran/31120] ICE with integer_exponentiation_1.f90 and -ffast-math
  2007-03-10 10:22 [Bug fortran/31120] New: ICE with integer_exponentiation_1.f90 and -ffast-math dominiq at lps dot ens dot fr
@ 2007-03-10 10:25 ` dominiq at lps dot ens dot fr
  2007-03-10 12:15 ` burnus at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: dominiq at lps dot ens dot fr @ 2007-03-10 10:25 UTC (permalink / raw)
  To: gcc-bugs



------- 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


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

* [Bug fortran/31120] ICE with integer_exponentiation_1.f90 and -ffast-math
  2007-03-10 10:22 [Bug fortran/31120] New: ICE with integer_exponentiation_1.f90 and -ffast-math dominiq at lps dot ens dot fr
  2007-03-10 10:25 ` [Bug fortran/31120] " dominiq at lps dot ens dot fr
@ 2007-03-10 12:15 ` burnus at gcc dot gnu dot org
  2007-03-10 12:33 ` tkoenig at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu dot org @ 2007-03-10 12:15 UTC (permalink / raw)
  To: gcc-bugs



-- 

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|0000-00-00 00:00:00         |2007-03-10 12:15:25
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31120


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

* [Bug fortran/31120] ICE with integer_exponentiation_1.f90 and -ffast-math
  2007-03-10 10:22 [Bug fortran/31120] New: ICE with integer_exponentiation_1.f90 and -ffast-math dominiq at lps dot ens dot fr
  2007-03-10 10:25 ` [Bug fortran/31120] " dominiq at lps dot ens dot fr
  2007-03-10 12:15 ` burnus at gcc dot gnu dot org
@ 2007-03-10 12:33 ` tkoenig at gcc dot gnu dot org
  2007-03-14 12:31 ` fxcoudert at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2007-03-10 12:33 UTC (permalink / raw)
  To: gcc-bugs



------- 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


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

* [Bug fortran/31120] ICE with integer_exponentiation_1.f90 and -ffast-math
  2007-03-10 10:22 [Bug fortran/31120] New: ICE with integer_exponentiation_1.f90 and -ffast-math dominiq at lps dot ens dot fr
                   ` (2 preceding siblings ...)
  2007-03-10 12:33 ` tkoenig at gcc dot gnu dot org
@ 2007-03-14 12:31 ` fxcoudert at gcc dot gnu dot org
  2007-03-14 13:58 ` dominiq at lps dot ens dot fr
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-14 12:31 UTC (permalink / raw)
  To: gcc-bugs



------- 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


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

* [Bug fortran/31120] ICE with integer_exponentiation_1.f90 and -ffast-math
  2007-03-10 10:22 [Bug fortran/31120] New: ICE with integer_exponentiation_1.f90 and -ffast-math dominiq at lps dot ens dot fr
                   ` (3 preceding siblings ...)
  2007-03-14 12:31 ` fxcoudert at gcc dot gnu dot org
@ 2007-03-14 13:58 ` dominiq at lps dot ens dot fr
  2007-03-14 14:02 ` fxcoudert at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: dominiq at lps dot ens dot fr @ 2007-03-14 13:58 UTC (permalink / raw)
  To: gcc-bugs



------- 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


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

* [Bug fortran/31120] ICE with integer_exponentiation_1.f90 and -ffast-math
  2007-03-10 10:22 [Bug fortran/31120] New: ICE with integer_exponentiation_1.f90 and -ffast-math dominiq at lps dot ens dot fr
                   ` (4 preceding siblings ...)
  2007-03-14 13:58 ` dominiq at lps dot ens dot fr
@ 2007-03-14 14:02 ` fxcoudert at gcc dot gnu dot org
  2007-03-14 14:27 ` dominiq at lps dot ens dot fr
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-14 14:02 UTC (permalink / raw)
  To: gcc-bugs



------- 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


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

* [Bug fortran/31120] ICE with integer_exponentiation_1.f90 and -ffast-math
  2007-03-10 10:22 [Bug fortran/31120] New: ICE with integer_exponentiation_1.f90 and -ffast-math dominiq at lps dot ens dot fr
                   ` (5 preceding siblings ...)
  2007-03-14 14:02 ` fxcoudert at gcc dot gnu dot org
@ 2007-03-14 14:27 ` dominiq at lps dot ens dot fr
  2007-03-15  8:24 ` dominiq at lps dot ens dot fr
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: dominiq at lps dot ens dot fr @ 2007-03-14 14:27 UTC (permalink / raw)
  To: gcc-bugs



------- 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


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

* [Bug fortran/31120] ICE with integer_exponentiation_1.f90 and -ffast-math
  2007-03-10 10:22 [Bug fortran/31120] New: ICE with integer_exponentiation_1.f90 and -ffast-math dominiq at lps dot ens dot fr
                   ` (6 preceding siblings ...)
  2007-03-14 14:27 ` dominiq at lps dot ens dot fr
@ 2007-03-15  8:24 ` dominiq at lps dot ens dot fr
  2007-03-15  8:52 ` dominiq at lps dot ens dot fr
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: dominiq at lps dot ens dot fr @ 2007-03-15  8:24 UTC (permalink / raw)
  To: gcc-bugs



------- 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


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

* [Bug fortran/31120] ICE with integer_exponentiation_1.f90 and -ffast-math
  2007-03-10 10:22 [Bug fortran/31120] New: ICE with integer_exponentiation_1.f90 and -ffast-math dominiq at lps dot ens dot fr
                   ` (7 preceding siblings ...)
  2007-03-15  8:24 ` dominiq at lps dot ens dot fr
@ 2007-03-15  8:52 ` dominiq at lps dot ens dot fr
  2007-03-17 19:59 ` fxcoudert at gcc dot gnu dot org
  2007-03-22  0:10 ` [Bug fortran/31120] [4.1/4.2 only] " fxcoudert at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: dominiq at lps dot ens dot fr @ 2007-03-15  8:52 UTC (permalink / raw)
  To: gcc-bugs



------- 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 passes            16445
# of unexpected failures        17
# 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


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

* [Bug fortran/31120] ICE with integer_exponentiation_1.f90 and -ffast-math
  2007-03-10 10:22 [Bug fortran/31120] New: ICE with integer_exponentiation_1.f90 and -ffast-math dominiq at lps dot ens dot fr
                   ` (8 preceding siblings ...)
  2007-03-15  8:52 ` dominiq at lps dot ens dot fr
@ 2007-03-17 19:59 ` fxcoudert at gcc dot gnu dot org
  2007-03-22  0:10 ` [Bug fortran/31120] [4.1/4.2 only] " fxcoudert at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-17 19:59 UTC (permalink / raw)
  To: gcc-bugs



------- 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=gcc&view=rev&rev=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


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

* [Bug fortran/31120] [4.1/4.2 only] ICE with integer_exponentiation_1.f90 and -ffast-math
  2007-03-10 10:22 [Bug fortran/31120] New: ICE with integer_exponentiation_1.f90 and -ffast-math dominiq at lps dot ens dot fr
                   ` (9 preceding siblings ...)
  2007-03-17 19:59 ` fxcoudert at gcc dot gnu dot org
@ 2007-03-22  0:10 ` fxcoudert at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-22  0:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from fxcoudert at gcc dot gnu dot org  2007-03-22 00:10 -------
I tried to see if it was a regression against g77, but it is not. Will not
backport to 4.2, and closing.


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.3.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31120


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

end of thread, other threads:[~2007-03-22  0:10 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-10 10:22 [Bug fortran/31120] New: ICE with integer_exponentiation_1.f90 and -ffast-math dominiq at lps dot ens dot fr
2007-03-10 10:25 ` [Bug fortran/31120] " dominiq at lps dot ens dot fr
2007-03-10 12:15 ` burnus at gcc dot gnu dot org
2007-03-10 12:33 ` tkoenig at gcc dot gnu dot org
2007-03-14 12:31 ` fxcoudert at gcc dot gnu dot org
2007-03-14 13:58 ` dominiq at lps dot ens dot fr
2007-03-14 14:02 ` fxcoudert at gcc dot gnu dot org
2007-03-14 14:27 ` dominiq at lps dot ens dot fr
2007-03-15  8:24 ` dominiq at lps dot ens dot fr
2007-03-15  8:52 ` dominiq at lps dot ens dot fr
2007-03-17 19:59 ` fxcoudert at gcc dot gnu dot org
2007-03-22  0:10 ` [Bug fortran/31120] [4.1/4.2 only] " fxcoudert at gcc dot gnu dot org

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).