public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/31262]  New: -fno-range-check can trigger ICE
@ 2007-03-19 12:24 fxcoudert at gcc dot gnu dot org
  2007-03-19 12:25 ` [Bug fortran/31262] " fxcoudert at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-19 12:24 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 984 bytes --]

$ cat uu.f90 
  print *, 7_8*huge(0_8)+17_8
  end
$ gfortran -static uu.f90 -fno-range-check
uu.f90: In function ‘MAIN__’:
uu.f90:1: internal compiler error: in gfc_conv_mpz_to_tree, at
fortran/trans-const.c:183

There's an assertion in gfc_conv_mpz_to_tree:
      /* We assume that all numbers are in range for its type, and that
         we never create a type larger than 2*HWI, which is the largest
         that the middle-end can handle.  */

It's wrong. Now that we have -fno-range-check, we should handle this in some
way, probably by a modulo operation.


-- 
           Summary: -fno-range-check can trigger ICE
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: ice-on-invalid-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fxcoudert at gcc dot gnu dot org


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


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

* [Bug fortran/31262] -fno-range-check can trigger ICE
  2007-03-19 12:24 [Bug fortran/31262] New: -fno-range-check can trigger ICE fxcoudert at gcc dot gnu dot org
  2007-03-19 12:25 ` [Bug fortran/31262] " fxcoudert at gcc dot gnu dot org
@ 2007-03-19 12:25 ` fxcoudert at gcc dot gnu dot org
  2007-03-20  9:27 ` [Bug fortran/31262] -fno-range-check with large integer values triggers ICE fxcoudert at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-19 12:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from fxcoudert at gcc dot gnu dot org  2007-03-19 12:24 -------
This is mine, I'm deep into these things right now :(


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2007-03-19 12:24:48
               date|                            |


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


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

* [Bug fortran/31262] -fno-range-check can trigger ICE
  2007-03-19 12:24 [Bug fortran/31262] New: -fno-range-check can trigger ICE fxcoudert at gcc dot gnu dot org
@ 2007-03-19 12:25 ` fxcoudert at gcc dot gnu dot org
  2007-03-19 12:25 ` fxcoudert at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-19 12:25 UTC (permalink / raw)
  To: gcc-bugs



-- 

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
   Last reconfirmed|2007-03-19 12:24:48         |2007-03-19 12:24:57
               date|                            |


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


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

* [Bug fortran/31262] -fno-range-check with large integer values triggers ICE
  2007-03-19 12:24 [Bug fortran/31262] New: -fno-range-check can trigger ICE fxcoudert at gcc dot gnu dot org
  2007-03-19 12:25 ` [Bug fortran/31262] " fxcoudert at gcc dot gnu dot org
  2007-03-19 12:25 ` fxcoudert at gcc dot gnu dot org
@ 2007-03-20  9:27 ` fxcoudert at gcc dot gnu dot org
  2007-03-22 22:52 ` fxcoudert at gcc dot gnu dot org
  2007-03-22 22:53 ` fxcoudert at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-20  9:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from fxcoudert at gcc dot gnu dot org  2007-03-20 09:27 -------
Here's a patch:

Index: trans-const.c
===================================================================
--- trans-const.c       (revision 123017)
+++ trans-const.c       (working copy)
@@ -165,23 +165,31 @@
     }
   else
     {
-      unsigned HOST_WIDE_INT words[2];
-      size_t count;
+      unsigned HOST_WIDE_INT *words;
+      size_t count, numb;

+      /* Determine the number of unsigned HOST_WIDE_INT that are required
+         for represent the value.  */
+      numb = 8*sizeof(HOST_WIDE_INT);
+      count = (mpz_sizeinbase (i, 2) + numb-1) / numb;
+      if (count < 2)
+       count = 2;
+      words = (unsigned HOST_WIDE_INT *) alloca (count *
sizeof(HOST_WIDE_INT));
+
       /* Since we know that the value is not zero (mpz_fits_slong_p),
         we know that at least one word will be written, but we don't know
         about the second.  It's quicker to zero the second word before
         than conditionally clear it later.  */
       words[1] = 0;
-
+      
       /* Extract the absolute value into words.  */
-      mpz_export (words, &count, -1, sizeof (HOST_WIDE_INT), 0, 0, i);
+      mpz_export (words, &count, -1, sizeof(HOST_WIDE_INT), 0, 0, i);

-      /* We assume that all numbers are in range for its type, and that
-        we never create a type larger than 2*HWI, which is the largest
-        that the middle-end can handle.  */
-      gcc_assert (count == 1 || count == 2);
-
+      /* We don't assume that all numbers are in range for its type.
+         However, we never create a type larger than 2*HWI, which is the
+        largest that the middle-end can handle. So, we only take the
+        first two elements of words, which is equivalent to wrapping the
+        value if it's larger than the type range.  */
       low = words[0];
       high = words[1];


And there's a small testcase, to see that the constant trees created for
overflowing values have the same value than the naturally overflowing
calculation done at run-time:

$ cat uu.f90 
  integer :: a
  integer(kind=8) :: b
  a = -3
  b = -huge(b) / 7
  a = a ** 73
  b = 7894_8 * b - 78941_8
  print *, (-3)**73, a
  print *, 7894_8 * (-huge(b) / 7) - 78941_8, b
  end
$ gfortran -fno-range-check uu.f90 && ./a.out
 -1534976995 -1534976995
  2635249153387000989  2635249153387000989


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
      Known to fail|                            |4.1.3 4.2.0 4.3.0
            Summary|-fno-range-check can trigger|-fno-range-check with large
                   |ICE                         |integer values triggers ICE


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


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

* [Bug fortran/31262] -fno-range-check with large integer values triggers ICE
  2007-03-19 12:24 [Bug fortran/31262] New: -fno-range-check can trigger ICE fxcoudert at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2007-03-20  9:27 ` [Bug fortran/31262] -fno-range-check with large integer values triggers ICE fxcoudert at gcc dot gnu dot org
@ 2007-03-22 22:52 ` fxcoudert at gcc dot gnu dot org
  2007-03-22 22:53 ` fxcoudert at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-22 22:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from fxcoudert at gcc dot gnu dot org  2007-03-22 22:52 -------
Subject: Bug 31262

Author: fxcoudert
Date: Thu Mar 22 22:51:50 2007
New Revision: 123136

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=123136
Log:
        PR fortran/31262

        * trans-const.c (gfc_conv_mpz_to_tree): Allow integer constants
        larger than twice the width of a HOST_WIDE_INT.

        * gfortran.dg/no_range_check_1.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/no_range_check_1.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-const.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug fortran/31262] -fno-range-check with large integer values triggers ICE
  2007-03-19 12:24 [Bug fortran/31262] New: -fno-range-check can trigger ICE fxcoudert at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2007-03-22 22:52 ` fxcoudert at gcc dot gnu dot org
@ 2007-03-22 22:53 ` fxcoudert at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-22 22:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from fxcoudert at gcc dot gnu dot org  2007-03-22 22:52 -------
Fixed on mainline, 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=31262


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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-19 12:24 [Bug fortran/31262] New: -fno-range-check can trigger ICE fxcoudert at gcc dot gnu dot org
2007-03-19 12:25 ` [Bug fortran/31262] " fxcoudert at gcc dot gnu dot org
2007-03-19 12:25 ` fxcoudert at gcc dot gnu dot org
2007-03-20  9:27 ` [Bug fortran/31262] -fno-range-check with large integer values triggers ICE fxcoudert at gcc dot gnu dot org
2007-03-22 22:52 ` fxcoudert at gcc dot gnu dot org
2007-03-22 22:53 ` 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).