public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/36153]  New: ICE on size with kind parameter
@ 2008-05-06 11:06 J dot Hogg at rl dot ac dot uk
  2008-05-06 14:43 ` [Bug fortran/36153] " burnus at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: J dot Hogg at rl dot ac dot uk @ 2008-05-06 11:06 UTC (permalink / raw)
  To: gcc-bugs

Use of an optional kind parameter on a call to the intrinsic size was added in
Fortran 2003, and is essential to avoid overflow when dealing with arrays
bigger than huge(0). The following example provides test code and demonstrates
this.
gfortran should warn that this is non-standard fortran 90/95 and fail
gracefully, and/or work as per the F2003 spec.

Thanks,
Jonathan.

[user@host] ~/bugs/gfortran-4.3/size_kind  $ gfortran-4.3 -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --program-suffix=-4.3
Thread model: posix
gcc version 4.3.0 (GCC)
[user@host] ~/bugs/gfortran-4.3/size_kind  $ gfortran-4.3 test_64.f90 
f951: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
[user@host] ~/bugs/gfortran-4.3/size_kind  $ cat test_64.f90 
program test_64
   implicit none

   integer, parameter :: long = selected_int_kind(18)
   integer, parameter :: short = kind(0)

   integer(long), parameter :: big_sz = huge(0_short)+1000_long
   integer(long), parameter :: max_32 = huge(0_short)
   integer, dimension(:), allocatable :: array

   integer(long) :: i

   print *, "2**31  = ", 2_long**31
   print *, "max_32 = ", max_32
   print *, "big_sz = ", big_sz

   allocate(array(big_sz))
   print *, "sz = ", size(array)
   print *, "sz = ", size(array, kind=long)
end program


-- 
           Summary: ICE on size with kind parameter
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: J dot Hogg at rl dot ac dot uk
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


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


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

* [Bug fortran/36153] ICE on size with kind parameter
  2008-05-06 11:06 [Bug fortran/36153] New: ICE on size with kind parameter J dot Hogg at rl dot ac dot uk
@ 2008-05-06 14:43 ` burnus at gcc dot gnu dot org
  2008-05-06 15:18 ` kargl at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: burnus at gcc dot gnu dot org @ 2008-05-06 14:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from burnus at gcc dot gnu dot org  2008-05-06 14:43 -------
Confirmed. Note: Using -std=f95 the kind= is properly rejected. 

==16567== Invalid read of size 4
==16567==    at 0x4605FD: gfc_resolve_expr (resolve.c:2310)
==16567==    by 0x465625: resolve_code (resolve.c:6195)
==16567==    by 0x468D1B: gfc_resolve_blocks (resolve.c:5988)
==16567==    by 0x46560C: resolve_code (resolve.c:6187)
==16567==    by 0x466F40: resolve_codes (resolve.c:9121)

I think the following comparison does not make sense for KIND= (I have only
glanced at it):

      for (arg = expr->value.function.actual; arg; arg = arg->next)
        {
          if (inquiry && arg->next != NULL && arg->next->expr)
            {
              if (arg->next->expr->expr_type != EXPR_CONSTANT)
                break;

              if ((int)mpz_get_si (arg->next->expr->value.integer)
                        < arg->expr->rank)
                break;

I think this function still assumes that one uses only DIM= and not KIND=. The
failing line is the mpz_get_si, although that should work? Allowed options are:

   SIZE (ARRAY [, DIM, KIND])


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |ice-on-valid-code
      Known to fail|                            |4.3.1 4.4.0
   Last reconfirmed|0000-00-00 00:00:00         |2008-05-06 14:43:06
               date|                            |


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


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

* [Bug fortran/36153] ICE on size with kind parameter
  2008-05-06 11:06 [Bug fortran/36153] New: ICE on size with kind parameter J dot Hogg at rl dot ac dot uk
  2008-05-06 14:43 ` [Bug fortran/36153] " burnus at gcc dot gnu dot org
@ 2008-05-06 15:18 ` kargl at gcc dot gnu dot org
  2008-08-29 23:21 ` [Bug fortran/36153] ICE on size with kind parameter [F2003] kargl at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: kargl at gcc dot gnu dot org @ 2008-05-06 15:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from kargl at gcc dot gnu dot org  2008-05-06 15:17 -------
The problem arises because fortran/trans-intrinsics.c and
libgfortran/intrinsics/size.c were not updated to deal with
the addition of the KIND keyword.  If you change the code to
use size(array, dim=1, kind=long), then the kind=long is
essentially ignored.  In your case, _gfortran_size1 is given
dim=long, which is dim=8, which of course segfaults.

To get a error message, add -std=f95 to your command line; 
otherwise, gfortran accepts most Fortran 2003 intrinsic 
subprograms by default.


-- 


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


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

* [Bug fortran/36153] ICE on size with kind parameter [F2003]
  2008-05-06 11:06 [Bug fortran/36153] New: ICE on size with kind parameter J dot Hogg at rl dot ac dot uk
  2008-05-06 14:43 ` [Bug fortran/36153] " burnus at gcc dot gnu dot org
  2008-05-06 15:18 ` kargl at gcc dot gnu dot org
@ 2008-08-29 23:21 ` kargl at gcc dot gnu dot org
  2008-09-06 15:30 ` burnus at gcc dot gnu dot org
  2008-09-06 15:57 ` burnus at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: kargl at gcc dot gnu dot org @ 2008-08-29 23:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from kargl at gcc dot gnu dot org  2008-08-29 23:20 -------
See

http://gcc.gnu.org/ml/gcc-patches/2008-08/msg02322.html


Your welcome.


-- 


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


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

* [Bug fortran/36153] ICE on size with kind parameter [F2003]
  2008-05-06 11:06 [Bug fortran/36153] New: ICE on size with kind parameter J dot Hogg at rl dot ac dot uk
                   ` (2 preceding siblings ...)
  2008-08-29 23:21 ` [Bug fortran/36153] ICE on size with kind parameter [F2003] kargl at gcc dot gnu dot org
@ 2008-09-06 15:30 ` burnus at gcc dot gnu dot org
  2008-09-06 15:57 ` burnus at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: burnus at gcc dot gnu dot org @ 2008-09-06 15:30 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from burnus at gcc dot gnu dot org  2008-09-06 15:29 -------
Subject: Bug 36153

Author: burnus
Date: Sat Sep  6 15:27:50 2008
New Revision: 140063

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=140063
Log:
2008-09-06  Steven G. Kargl  <kargls@comcast.net>

       PR fortran/36153
       * fortran/resolve.c (resolve_function): Shortcircuit for SIZE and
       UBOUND if 2nd argument is KIND.

2008-09-06  Tobias Burnus  <burnus@net-b.de>

       PR fortran/36153
       * gfortran.dg/size_kind.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/size_kind.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug fortran/36153] ICE on size with kind parameter [F2003]
  2008-05-06 11:06 [Bug fortran/36153] New: ICE on size with kind parameter J dot Hogg at rl dot ac dot uk
                   ` (3 preceding siblings ...)
  2008-09-06 15:30 ` burnus at gcc dot gnu dot org
@ 2008-09-06 15:57 ` burnus at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: burnus at gcc dot gnu dot org @ 2008-09-06 15:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from burnus at gcc dot gnu dot org  2008-09-06 15:56 -------
FIXED on the trunk (4.4.0)


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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


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

end of thread, other threads:[~2008-09-06 15:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-06 11:06 [Bug fortran/36153] New: ICE on size with kind parameter J dot Hogg at rl dot ac dot uk
2008-05-06 14:43 ` [Bug fortran/36153] " burnus at gcc dot gnu dot org
2008-05-06 15:18 ` kargl at gcc dot gnu dot org
2008-08-29 23:21 ` [Bug fortran/36153] ICE on size with kind parameter [F2003] kargl at gcc dot gnu dot org
2008-09-06 15:30 ` burnus at gcc dot gnu dot org
2008-09-06 15:57 ` burnus 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).