resolve.c: Prevent segfault on illegal input.
authorAndre Vehreschild <vehre@gmx.de>
Mon, 16 Mar 2015 10:29:59 +0000 (11:29 +0100)
committerAndre Vehreschild <vehre@gcc.gnu.org>
Mon, 16 Mar 2015 10:29:59 +0000 (11:29 +0100)
gcc/fortran/ChangeLog:

2015-03-16  Andre Vehreschild  <vehre@gmx.de>

* resolve.c: Prevent segfault on illegal input.

gcc/testsuite/ChangeLog:

2015-03-16  Andre Vehreschild  <vehre@gmx.de>

* gfortran.dg/pointer_2.f90: New test.

From-SVN: r221455

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pointer_2.f90 [new file with mode: 0644]

index 30107c977af8580872eac1e4e4f6a33e5366a50d..a7071968dd34c18b609fd4c1158031a6b2fb3653 100644 (file)
@@ -1,3 +1,7 @@
+2015-03-16  Andre Vehreschild  <vehre@gmx.de>
+
+       * resolve.c: Prevent segfault on illegal input.
+
 2015-03-14  Mikael Morin  <mikael@gcc.gnu.org>
 
        PR fortran/61138
index 942a9ad9ac4df5d432009584fc533a2e48d0a420..465cf2ba8cf1782e517afe56df70c01bbe85e29a 100644 (file)
@@ -2639,6 +2639,10 @@ found:
     expr->ts = sym->ts;
   expr->value.function.name = sym->name;
   expr->value.function.esym = sym;
+  /* Prevent crash when sym->ts.u.derived->components is not set due to previous
+     error(s).  */
+  if (sym->ts.type == BT_CLASS && !CLASS_DATA (sym))
+    return MATCH_ERROR;
   if (sym->ts.type == BT_CLASS && CLASS_DATA (sym)->as)
     expr->rank = CLASS_DATA (sym)->as->rank;
   else if (sym->as != NULL)
index edfdf6bd28f19fde8e318998cbaa97b9422679b1..55d00b076d80d6e4bd7dfa1b17d6a3a40da246dc 100644 (file)
@@ -1,3 +1,7 @@
+2015-03-16  Andre Vehreschild  <vehre@gmx.de>
+
+       * gfortran.dg/pointer_2.f90: New test.
+
 2015-03-16  Eric Botcazou  <ebotcazou@adacore.com>
 
        * testsuite/g++.dg/pr65049.C: New test.
diff --git a/gcc/testsuite/gfortran.dg/pointer_2.f90 b/gcc/testsuite/gfortran.dg/pointer_2.f90
new file mode 100644 (file)
index 0000000..a9b039d
--- /dev/null
@@ -0,0 +1,18 @@
+! { dg-do compile }
+! Check that the compiler reports the errors, but does not segfault.
+! Contributed by: Andre Vehreschild  <vehre@gcc.gnu.org>
+!
+program test
+    implicit none
+    class(*), pointer :: P
+    class(*), allocatable :: P2
+
+    allocate(P2, source=convertType(P))
+
+contains
+
+  function convertType(in) ! { dg-error "must be dummy, allocatable or pointer" }
+    class(*), intent(in) :: in
+    class(*) :: convertType
+  end function
+end program test