[committed,Fortran] PR91586 Fix ICE on invalid code with CLASS
diff mbox series

Message ID a5c6a1dc-eacb-2888-1645-7e7a30700db9@codesourcery.com
State New
Headers show
Series
  • [committed,Fortran] PR91586 Fix ICE on invalid code with CLASS
Related show

Commit Message

Tobias Burnus Oct. 18, 2019, 12:46 p.m. UTC
Re-instate error message which got by dereferrencing a NULL pointer.

Commited as r277153 to the trunk.
Committed as r277154 to the GCC 9 branch (as it was a 9/10 regression).

Thanks,

Tobias

Patch
diff mbox series

commit f9aef7e7d320df8560e602d863e97ea324e68644
Author: burnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Fri Oct 18 12:04:31 2019 +0000

    Fortran] PR91586 Fix ICE on invalid code with CLASS
    
            gcc/fortran/
            PR fortran/91586
            * class.c (gfc_find_derived_vtab): Return NULL
            instead of deref'ing NULL pointer.
    
            gcc/testsuite/
            PR fortran/91586
            * gfortran.dg/class_71.f90: New.
    
    
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@277153 138bc75d-0d04-0410-961f-82ee72b054a4

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 1dbc890f5da..8a1beeafa01 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,9 @@ 
+2019-10-18  Tobias Burnus  <tobias@codesourcery.com>
+
+	PR fortran/91586
+	* class.c (gfc_find_derived_vtab): Return NULL
+	instead of deref'ing NULL pointer.
+
 2019-10-15  James Norris  <jnorris@codesourcery.com>
 	    Tobias Burnus  <tobias@codesourcery.com>
 
diff --git a/gcc/fortran/class.c b/gcc/fortran/class.c
index 8a1f43f116c..9117121e5fe 100644
--- a/gcc/fortran/class.c
+++ b/gcc/fortran/class.c
@@ -2241,6 +2241,9 @@  gfc_find_derived_vtab (gfc_symbol *derived)
   if (!derived->attr.unlimited_polymorphic && derived->attr.is_class)
     derived = gfc_get_derived_super_type (derived);
 
+  if (!derived)
+    return NULL;
+
   /* Find the gsymbol for the module of use associated derived types.  */
   if ((derived->attr.use_assoc || derived->attr.used_in_submodule)
        && !derived->attr.vtype && !derived->attr.is_class)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b783c8dede3..4e817eb1371 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@ 
+2019-10-18  Tobias Burnus  <tobias@codesourcery.com>
+
+	PR fortran/91586
+	* gfortran.dg/class_71.f90: New.
+
 2019-10-18  Georg-Johann Lay  <avr@gjlay.de>
 
 	Fix some fallout for small targets.
diff --git a/gcc/testsuite/gfortran.dg/class_71.f90 b/gcc/testsuite/gfortran.dg/class_71.f90
new file mode 100644
index 00000000000..bc0ffcd2305
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/class_71.f90
@@ -0,0 +1,13 @@ 
+! { dg-do compile }
+!
+! PR fortran/91586
+!
+! Contributed by G. Steinmetz
+!
+program p
+   type t
+      class(*), allocatable :: a
+   end type
+   class(t) :: x, y  ! { dg-error "must be dummy, allocatable or pointer" }
+   y = x  ! { dg-error "Nonallocatable variable must not be polymorphic in intrinsic assignment" }
+end