Bug 37999 - Fortran shape and kind intrinsic
Summary: Fortran shape and kind intrinsic
Status: RESOLVED WORKSFORME
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.0.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-02 23:33 UTC by Brian T. Smith
Modified: 2008-11-11 05:28 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Brian T. Smith 2008-11-02 23:33:46 UTC
Shape intrinsic does not allow scalar arguments as required by f90/f95/f03 standards. Example code follows:
program test_shape ! Segmentation fault generated when executable executed
   integer :: i
   print *, shape( i )  ! Shape of a scalar allowed by f90, f95, f03
                        ! standards.
end program test_shape


Kind intrinsic with character argument in type declaration fails: Example follows:
! Compiler version:
! GNU Fortran (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu3)
! Copyright (C) 2007 Free Software Foundation, Inc.

character (len = 3, kind = kind("a" )  c  ! Compiler fails with internal error -- invalid syntax
! character (len = 3, kind = kind("a") )  c  ! Fails compilation -- invalid kind
!                                              value returned -- that is, minus
!                                              integer huge.  Notice the
!                                              kind("a") is correctly returned
!                                              as 1 in print statement below and
!                                              kind=1 works in a character
!                                              declaration.
! character (len = 3, kind = 1)  c  ! Works

   c = "b"
   print *, kind("a"), c
end program
Comment 1 kargls 2008-11-03 00:00:14 UTC
Code works with 4.3.2 and trunk.

Note you probably want to

1) Update to a 4.3.2 or newer compiler.
2) Change the example to 

   program test_shape
   integer :: i
   print *, size(shape(i))  ! Shape of a scalar allowed by f95 standards.
   end program test_shape

   because shape(i) is a zero sized array.
Comment 2 Brian T. Smith 2008-11-03 16:32:10 UTC
Subject: Re:  Fortran shape and kind intrinsic

Thanks for the response.  I will download the latest compiler, which I 
thought I had.  I guess the autoupdate for my Mint Linux is not working 
promptly or this has been updated in the last two weeks.  With the new 
version, I will check the second problem I reported as well and report back 
(kind intrinsic with character argument in a type declararation statement).

Thanks again and appreciate you help -- you have saved me of creating a 
workaround for the GNU compilers for my large application code for the shape 
intrinsic  -- the code I gave is the simplest extraction I could think of 
but your recommendation for this test is clearly better.
----- Original Message ----- 
From: "kargl at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: <carbess@swcp.com>
Sent: Sunday, November 02, 2008 5:00 PM
Subject: [Bug fortran/37999] Fortran shape and kind intrinsic


>
>
> ------- Comment #1 from kargl at gcc dot gnu dot org  2008-11-03 
> 00:00 -------
> Code works with 4.3.2 and trunk.
>
> Note you probably want to
>
> 1) Update to a 4.3.2 or newer compiler.
> 2) Change the example to
>
>   program test_shape
>   integer :: i
>   print *, size(shape(i))  ! Shape of a scalar allowed by f95 standards.
>   end program test_shape
>
>   because shape(i) is a zero sized array.
>
>
> -- 
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37999
>
> ------- You are receiving this mail because: -------
> You reported the bug, or are watching the reporter.
> 

Comment 3 kargls 2008-11-03 18:41:42 UTC
(In reply to comment #2)
> With the new  version, I will check the second problem I reported
> as well and report back  (kind intrinsic with character argument
> in a type declararation statement)

The 2nd problem is also fixed in 4.3.2 and newer gfortran. 

   character (len = 3, kind = kind("a" )  c
   c = "b"
   print *, kind("a"), c
   end program

troutmask:kargl[203] ~/../sgk/work/4x/bin/gfortran -static -o z t.f90
t.f90:1.42:

   character (len = 3, kind = kind("a" )  c
                                         1
Error: Syntax error in CHARACTER declaration at (1)
t.f90:2.7:

   c = "b"
      1
Error: Can't convert CHARACTER(1) to REAL(4) at (1)

The second error is a side effect of the first error.
Comment 4 Tobias Burnus 2008-11-03 22:17:26 UTC
"print *, shape( i )"

That program works here with GCC 4.1.3, 4.2.1 and 4.3.3-20081002 of openSUSE, and with 4.3.3-20081103 and 4.4.0 of today. I not even get any valgrind error.


Character tests:
I can reproduce the ICE with 4.2, it works with 4.3/4.4.


> I will download the latest compiler, which I thought I had.
> I guess the autoupdate for my Mint Linux is not working 
> promptly or this has been updated in the last two weeks.

Note: Distributions are slow at updating the compiler as it is the core part and can cause a lot of problem.

4.3.0 was released 2008-03-05 and 4.3.x is said to be a very well working version from the C/middle-end part. Also the Fortran part is in a pretty good shape.

4.4.0 is not yet released but exists as developer version, which is daily updated but can only get regression fixes. Nightly Linux builds are available from: http://gcc.gnu.org/wiki/GFortranBinaries
Comment 5 Jerry DeLisle 2008-11-11 05:28:29 UTC
Closing, not a bug any more.