Bug 54435 - [4.7/4.8 Regression] ICE with SELECT TYPE on a non-CLASS object
Summary: [4.7/4.8 Regression] ICE with SELECT TYPE on a non-CLASS object
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.8.0
: P4 normal
Target Milestone: 4.7.2
Assignee: janus
URL:
Keywords: ice-on-invalid-code
: 54434 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-08-31 08:46 UTC by Tobias Burnus
Modified: 2012-09-10 13:10 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-08-31 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2012-08-31 08:46:39 UTC
It crashes in match.c's gfc_match_select_type:

  class_array = expr1->expr_type == EXPR_VARIABLE
                  && expr1->ts.type != BT_UNKNOWN
                  && CLASS_DATA (expr1)
                  ...

as for obvious reasons, a non-BT_CLASS doesn't have CLASS_DATA.


Test case, reported by xarthisius on #gfortran:

subroutine foo(x)
!  type(*) :: x
  integer :: x
  select type (x)
  end select type
end
Comment 1 Tobias Burnus 2012-08-31 08:48:32 UTC
As postscript: Non BT_CLASS should be directly rejected. From F2008:

C837 (R847)  The selector in a select-type-stmt shall be polymorphic.
Comment 2 Tobias Burnus 2012-08-31 08:51:22 UTC
*** Bug 54434 has been marked as a duplicate of this bug. ***
Comment 3 Tobias Burnus 2012-08-31 09:19:24 UTC
I marked it as regression as with 4.6 it doesn't ICE ("class_array =" is new in 4.7). Though, the error message of 4.6 is not really that helpful:

  end select type
                 1
Error: Syntax error in END SELECT statement at (1)
Comment 4 janus 2012-08-31 13:15:24 UTC
(In reply to comment #1)
> As postscript: Non BT_CLASS should be directly rejected. From F2008:
> 
> C837 (R847)  The selector in a select-type-stmt shall be polymorphic.

We have such a check in resolve_select_type, which obviously comes too late for gfc_match_select_type.
Comment 5 janus 2012-08-31 14:03:21 UTC
This kills the ICE and gets us back at least to the 4.6 behavior (see comment #3):


Index: gcc/fortran/match.c
===================================================================
--- gcc/fortran/match.c	(revision 190419)
+++ gcc/fortran/match.c	(working copy)
@@ -5367,10 +5367,10 @@ gfc_match_select_type (void)
      array, which can have a reference, from other expressions that
      have references, such as derived type components, and are not
      allowed by the standard.
-     TODO; see is it is sufficient to exclude component and substring
+     TODO: see if it is sufficient to exclude component and substring
      references.  */
   class_array = expr1->expr_type == EXPR_VARIABLE
-		  && expr1->ts.type != BT_UNKNOWN
+		  && expr1->ts.type == BT_CLASS
 		  && CLASS_DATA (expr1)
 		  && (strcmp (CLASS_DATA (expr1)->name, "_data") == 0)
 		  && (CLASS_DATA (expr1)->attr.dimension
Comment 6 janus 2012-08-31 14:58:28 UTC
(In reply to comment #3)
> Though, the error message of 4.6 is not really that helpful:
> 
>   end select type
>                  1
> Error: Syntax error in END SELECT statement at (1)

Well, it's helpful in that it spots a syntax error in the test case: The correct form is END SELECT.

If ones fixes the test case in this respect ...

subroutine foo(x)
  integer :: x
  select type (x)
  end select
end

... then it is rejected by the patch in comment 5 with the correct error message:

  select type (x)
                 1   
Error: Selector shall be polymorphic in SELECT TYPE statement at (1)


I'll start a regtest of the the patch now ...
Comment 7 janus 2012-09-01 13:25:53 UTC
(In reply to comment #6)
> I'll start a regtest of the the patch now ...

Apparently there have been some (middle-end?) issues on the trunk lately, causing a good number of testsuite failures. However, at r190845, the patch in comment 5 regtests cleanly.

I will commit to trunk as obvious soon. What about 4.7?
Comment 8 janus 2012-09-04 08:03:14 UTC
Author: janus
Date: Tue Sep  4 08:03:09 2012
New Revision: 190910

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=190910
Log:
2012-09-04  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/54435
	PR fortran/54443
	* match.c (gfc_match_select_type): Make sure to only access CLASS_DATA
	for BT_CLASS.

2012-09-04  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/54243
	PR fortran/54244
	* gfortran.dg/select_type_29.f03: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/select_type_29.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/match.c
    trunk/gcc/testsuite/ChangeLog
Comment 9 janus 2012-09-10 12:10:27 UTC
Author: janus
Date: Mon Sep 10 12:10:12 2012
New Revision: 191135

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=191135
Log:
2012-09-10  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/54435
	PR fortran/54443
	* match.c (gfc_match_select_type): Make sure to only access CLASS_DATA
	for BT_CLASS.

2012-09-10  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/54435
	PR fortran/54443
	* gfortran.dg/select_type_29.f03: New.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/gfortran.dg/select_type_29.f03
Modified:
    branches/gcc-4_7-branch/gcc/fortran/ChangeLog
    branches/gcc-4_7-branch/gcc/fortran/match.c
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
Comment 10 janus 2012-09-10 12:14:00 UTC
Fixed on trunk and 4.7. Closing.
Comment 11 paul.richard.thomas@gmail.com 2012-09-10 13:10:30 UTC
Dear Janus,

Thanks for dealing with that.

Cheers

Paul

On 10 September 2012 14:14, janus at gcc dot gnu.org
<gcc-bugzilla@gcc.gnu.org> wrote:
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54435
>
> janus at gcc dot gnu.org changed:
>
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>              Status|ASSIGNED                    |RESOLVED
>          Resolution|                            |FIXED
>
> --- Comment #10 from janus at gcc dot gnu.org 2012-09-10 12:14:00 UTC ---
> Fixed on trunk and 4.7. Closing.
>
> --
> Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
> ------- You are receiving this mail because: -------
> You are on the CC list for the bug.