[Bug fortran/82934] [6/7/8 Regression] Segfault on assumed character length in allocate

2017-12-09 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82934

kargl at gcc dot gnu.org changed:

   What|Removed |Added

 Status|REOPENED|RESOLVED
 Resolution|--- |FIXED

--- Comment #12 from kargl at gcc dot gnu.org ---
Testing for F2008:C631 is fixed on truck.

[Bug fortran/82934] [6/7/8 Regression] Segfault on assumed character length in allocate

2017-12-09 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82934
Bug 82934 depends on bug 83318, which changed state.

Bug 83318 Summary: Illegal program causes internal compiler error with tags 
gfc_trans_allocate, at fortran/trans-stmt.c:5646  and  Aborted (program f951)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83318

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

[Bug fortran/82934] [6/7/8 Regression] Segfault on assumed character length in allocate

2017-12-09 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82934

--- Comment #11 from kargl at gcc dot gnu.org ---
Author: kargl
Date: Sat Dec  9 19:53:55 2017
New Revision: 255524

URL: https://gcc.gnu.org/viewcvs?rev=255524&root=gcc&view=rev
Log:
2017-12-09  Steven G. Kargl  

PR fortran/82934
PR fortran/83318
* match.c (gfc_match_allocate): Enforce F2008:C631.

2017-12-09  Steven G. Kargl  

PR fortran/82934
PR fortran/83318
* gfortran.dg/allocate_assumed_charlen_2.f90: new test.

Added:
trunk/gcc/testsuite/gfortran.dg/allocate_assumed_charlen_2.f90
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/match.c
trunk/gcc/testsuite/ChangeLog

[Bug fortran/82934] [6/7/8 Regression] Segfault on assumed character length in allocate

2017-12-07 Thread sgk at troutmask dot apl.washington.edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82934

--- Comment #10 from Steve Kargl  ---
On Fri, Dec 08, 2017 at 01:14:44AM +, sgk at troutmask dot
apl.washington.edu wrote:
> 
> I don't know how I missed F2008:C631
> 
> C631 (R626) A type-param-value in a type-spec shall be an asterisk if
>and only if each allocate-object is a dummy argument for which the
>corresponding type parameter is assumed.
> 
> This is going to make the fix for 83318 real ugly.
> 
   character(len=42), allocatable :: foo
   character(len=22), allocatable :: foofoo

   call alloc( foo , foofoo)

   if (len(foo) .ne. 42) call abort
   if (len(foofoo) .ne. 22) call abort

contains

   subroutine alloc( bar, barbar )
  character(len=*), allocatable  :: bar
  character(len=22), allocatable :: barbar
  allocate(character(len=*) :: bar , barbar) ! <= Here!
   end subroutine

end

gfcx  z a.f90
f951: internal compiler error: Segmentation fault
0xb5af0f crash_signal
../../gcc/gcc/toplev.c:325
0x75eb9a gfc_dep_compare_expr(gfc_expr*, gfc_expr*)
../../gcc/gcc/fortran/dependency.c:363
0x741636 resolve_allocate_expr
../../gcc/gcc/fortran/resolve.c:7487
0x741636 resolve_allocate_deallocate
../../gcc/gcc/fortran/resolve.c:7879
0x733115 gfc_resolve_code(gfc_code*, gfc_namespace*)
../../gcc/gcc/fortran/resolve.c:11314
0x735b4f resolve_codes
../../gcc/gcc/fortran/resolve.c:16433

[Bug fortran/82934] [6/7/8 Regression] Segfault on assumed character length in allocate

2017-12-07 Thread sgk at troutmask dot apl.washington.edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82934

--- Comment #9 from Steve Kargl  ---
On Fri, Dec 08, 2017 at 12:52:31AM +, sgk at troutmask dot
apl.washington.edu wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82934
> 
> --- Comment #8 from Steve Kargl  ---
> On Fri, Dec 08, 2017 at 12:29:50AM +, kargl at gcc dot gnu.org wrote:
> > 
> >   allocate( character(len=*) :: bar )
> > 
> > However, the type-spec in the allocate statement does coincide with
> 
> s/does/does not
> 
> > the declaration of a dummy argument, or appear in SELECT TYPE, or
> > in the declaration of a named constant.  The * cannot appear here.
> > 
> >end subroutine
> 

Is it the weekend yet?  :(

I don't know how I missed F2008:C631

C631 (R626) A type-param-value in a type-spec shall be an asterisk if
   and only if each allocate-object is a dummy argument for which the
   corresponding type parameter is assumed.

This is going to make the fix for 83318 real ugly.

[Bug fortran/82934] [6/7/8 Regression] Segfault on assumed character length in allocate

2017-12-07 Thread sgk at troutmask dot apl.washington.edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82934

--- Comment #8 from Steve Kargl  ---
On Fri, Dec 08, 2017 at 12:29:50AM +, kargl at gcc dot gnu.org wrote:
> 
>   allocate( character(len=*) :: bar )
> 
> However, the type-spec in the allocate statement does coincide with

s/does/does not

> the declaration of a dummy argument, or appear in SELECT TYPE, or
> in the declaration of a named constant.  The * cannot appear here.
> 
>end subroutine

[Bug fortran/82934] [6/7/8 Regression] Segfault on assumed character length in allocate

2017-12-07 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82934

kargl at gcc dot gnu.org changed:

   What|Removed |Added

   Keywords|ice-on-valid-code   |
 Status|RESOLVED|REOPENED
 CC||kargl at gcc dot gnu.org
 Depends on||83318
 Resolution|FIXED   |---

--- Comment #7 from kargl at gcc dot gnu.org ---
I believe that this code is invalid Fortran.  Fortran 2008 states

An asterisk as a type-param-value specifies that a length type
parameter is an assumed type parameter.  It is used for a dummy
argument to assume the type parameter value from the effective
argument, for an associate name in a SELECT TYPE construct to
assume the type parameter value from the corresponding selector,
and for a named constant of type character to assume the character
length from the constant-expr .

In this code,

   subroutine alloc( bar )

  character(len=*), allocatable :: bar

bar is the dummy argument, so a type-spec with * can appear
here.

  allocate( character(len=*) :: bar )

However, the type-spec in the allocate statement does coincide with
the declaration of a dummy argument, or appear in SELECT TYPE, or
in the declaration of a named constant.  The * cannot appear here.

   end subroutine

The correct subroutine is simply

   subroutine alloc( bar )
  character(len=*), allocatable :: bar
  allocate( bar )
   end subroutine

It's not clear to me if Paul's patch needs to be removed
as it appears to set a possibly dangling pointer to NULL


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83318
[Bug 83318] Illegal program causes internal compiler error with tags
gfc_trans_allocate, at fortran/trans-stmt.c:5646  and  Aborted (program f951)

[Bug fortran/82934] [6/7/8 Regression] Segfault on assumed character length in allocate

2017-11-14 Thread pault at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82934

Paul Thomas  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #6 from Paul Thomas  ---
This is now fixed on all three branches.

Thanks to self for reporting it :-)

Paul

[Bug fortran/82934] [6/7/8 Regression] Segfault on assumed character length in allocate

2017-11-14 Thread pault at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82934

--- Comment #5 from Paul Thomas  ---
Author: pault
Date: Tue Nov 14 17:38:38 2017
New Revision: 254733

URL: https://gcc.gnu.org/viewcvs?rev=254733&root=gcc&view=rev
Log:
2017-11-13  Paul Thomas  

Backport from trunk
PR fortran/82934
* trans-stmt.c (gfc_trans_allocate): Remove the gcc_assert on
null string length for assumed length typespec and set
expr3_esize to NULL_TREE;

2017-11-13  Paul Thomas  

Backport from trunk
PR fortran/82934
* gfortran.dg/allocate_assumed_charlen_1.f90: New test.


Added:
   
branches/gcc-6-branch/gcc/testsuite/gfortran.dg/allocate_assumed_charlen_1.f90
Modified:
branches/gcc-6-branch/gcc/fortran/ChangeLog
branches/gcc-6-branch/gcc/fortran/trans-stmt.c
branches/gcc-6-branch/gcc/testsuite/ChangeLog

[Bug fortran/82934] [6/7/8 Regression] Segfault on assumed character length in allocate

2017-11-13 Thread pault at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82934

--- Comment #4 from Paul Thomas  ---
Author: pault
Date: Mon Nov 13 20:46:08 2017
New Revision: 254709

URL: https://gcc.gnu.org/viewcvs?rev=254709&root=gcc&view=rev
Log:
2017-11-13  Paul Thomas  

Backport from trunk
PR fortran/82934
* trans-stmt.c (gfc_trans_allocate): Remove the gcc_assert on
null string length for assumed length typespec and set
expr3_esize to NULL_TREE;

2017-11-13  Paul Thomas  

Backport from trunk
PR fortran/82934
* gfortran.dg/allocate_assumed_charlen_1.f90: New test.


Added:
   
branches/gcc-7-branch/gcc/testsuite/gfortran.dg/allocate_assumed_charlen_1.f90
Modified:
branches/gcc-7-branch/gcc/fortran/ChangeLog
branches/gcc-7-branch/gcc/fortran/trans-stmt.c
branches/gcc-7-branch/gcc/testsuite/ChangeLog

[Bug fortran/82934] [6/7/8 Regression] Segfault on assumed character length in allocate

2017-11-10 Thread pault at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82934

--- Comment #3 from Paul Thomas  ---
(In reply to Dominique d'Humieres from comment #1)
> The test gives the expected result with gfortran 4.8 and 4.9. The change in
> behavior occurred between revisions r221412 + 3 patches (2015-03-13, works)
> and r2214164 + 3 patches (2015-03-16, ICE).

Oddly, the fortran ChangeLog shows nothing between these dates that one could
implicate.

As you will see, the fix was trivial. I am just about to post it on the list
and will apply it to 6- and 7-branches over the weekend. Even if not a
regression, it does prevent an ICE in a particularly robust way :-)

Thanks for investigating.

Paul

[Bug fortran/82934] [6/7/8 Regression] Segfault on assumed character length in allocate

2017-11-10 Thread pault at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82934

--- Comment #2 from Paul Thomas  ---
Author: pault
Date: Fri Nov 10 12:24:24 2017
New Revision: 254624

URL: https://gcc.gnu.org/viewcvs?rev=254624&root=gcc&view=rev
Log:
2017-11-10  Paul Thomas  

PR fortran/82934
* trans-stmt.c (gfc_trans_allocate): Remove the gcc_assert on
null string length for assumed length typespec and set
expr3_esize to NULL_TREE;

2017-11-10  Paul Thomas  

PR fortran/82934
* gfortran.dg/allocate_assumed_charlen_1.f90: New test.


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

[Bug fortran/82934] [6/7/8 Regression] Segfault on assumed character length in allocate

2017-11-10 Thread dominiq at lps dot ens.fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82934

Dominique d'Humieres  changed:

   What|Removed |Added

   Priority|P3  |P4
 Status|UNCONFIRMED |NEW
  Known to work||4.9.3
   Keywords||ice-on-valid-code
   Last reconfirmed||2017-11-10
 Ever confirmed|0   |1
Summary|Segfault on assumed |[6/7/8 Regression] Segfault
   |character length in |on assumed character length
   |allocate|in allocate
  Known to fail||5.5.0, 6.4.0, 7.2.0, 8.0

--- Comment #1 from Dominique d'Humieres  ---
The test gives the expected result with gfortran 4.8 and 4.9. The change in
behavior occurred between revisions r221412 + 3 patches (2015-03-13, works) and
r2214164 + 3 patches (2015-03-16, ICE).