re PR fortran/83149 ([6- and 7-branches] Missing test for sym->ns->proc_name: crash_s...
authorPaul Thomas <pault@gcc.gnu.org>
Fri, 23 Feb 2018 16:22:28 +0000 (16:22 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Fri, 23 Feb 2018 16:22:28 +0000 (16:22 +0000)
2018-02-23  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/83149
* trans-decl.c (gfc_finish_var_decl): Test sym->ns->proc_name
before accessing its components.

2018-02-23  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/83149
* gfortran.dg/pr83149_1.f90: New test.
* gfortran.dg/pr83149.f90: Additional source for previous.

From-SVN: r257934

gcc/fortran/ChangeLog
gcc/fortran/trans-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr83149.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/pr83149_1.f90 [new file with mode: 0644]

index c26c67f52ce84af303438147b75d954146c98065..60469d08eaacb2a560434f4a7a6222f4c067bf52 100644 (file)
@@ -1,3 +1,9 @@
+2018-02-23  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/83149
+       * trans-decl.c (gfc_finish_var_decl): Test sym->ns->proc_name
+       before accessing its components.
+
 2018-02-23  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/83148
index c233a0ee81f7c7b172bfd081c66c001a2ff7b137..6742d2e16b06aadb7382f873e6aa22e9852cf731 100644 (file)
@@ -609,10 +609,12 @@ gfc_finish_var_decl (tree decl, gfc_symbol * sym)
      function scope.  */
   if (current_function_decl != NULL_TREE)
     {
-      if (sym->ns->proc_name->backend_decl == current_function_decl
-         || sym->result == sym)
+      if (sym->ns->proc_name
+         && (sym->ns->proc_name->backend_decl == current_function_decl
+             || sym->result == sym))
        gfc_add_decl_to_function (decl);
-      else if (sym->ns->proc_name->attr.flavor == FL_LABEL)
+      else if (sym->ns->proc_name
+              && sym->ns->proc_name->attr.flavor == FL_LABEL)
        /* This is a BLOCK construct.  */
        add_decl_as_local (decl);
       else
@@ -704,7 +706,8 @@ gfc_finish_var_decl (tree decl, gfc_symbol * sym)
     }
 
   /* Keep variables larger than max-stack-var-size off stack.  */
-  if (!sym->ns->proc_name->attr.recursive && !sym->attr.automatic
+  if (!(sym->ns->proc_name && sym->ns->proc_name->attr.recursive)
+      && !sym->attr.automatic
       && INTEGER_CST_P (DECL_SIZE_UNIT (decl))
       && !gfc_can_put_var_on_stack (DECL_SIZE_UNIT (decl))
         /* Put variable length auto array pointers always into stack.  */
index cbd0160288a933d4815464b801a1e7bd86316711..dfe208d7fddad1939511adbe337b3a142dae5e0e 100644 (file)
@@ -1,3 +1,9 @@
+2018-02-23  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/83149
+       * gfortran.dg/pr83149_1.f90: New test.
+       * gfortran.dg/pr83149.f90: Additional source for previous.
+
 2018-02-23  Segher Boessenkool  <segher@kernel.crashing.org>
 
        PR testsuite/80551
diff --git a/gcc/testsuite/gfortran.dg/pr83149.f90 b/gcc/testsuite/gfortran.dg/pr83149.f90
new file mode 100644 (file)
index 0000000..fc0607e
--- /dev/null
@@ -0,0 +1,14 @@
+! Compiled with pr83149_1.f90
+!
+module mod1
+  integer :: ncells
+end module
+
+module mod2
+contains
+  function get() result(array)
+    use mod1
+    real array(ncells)
+    array = 1.0
+  end function
+end module
diff --git a/gcc/testsuite/gfortran.dg/pr83149_1.f90 b/gcc/testsuite/gfortran.dg/pr83149_1.f90
new file mode 100644 (file)
index 0000000..3a8f5d5
--- /dev/null
@@ -0,0 +1,24 @@
+! Compiled with pr83149.f90
+! { dg-do run }
+! { dg-options "-fno-whole-file" }
+! { dg-compile-aux-modules "pr83149.f90" }
+! { dg-additional-sources pr83149.f90 }
+!
+! Contributed by Neil Carlson  <neil.n.carlson@gmail.com>
+!
+subroutine sub(s)
+  use mod2
+  real :: s
+  s = sum(get())
+end
+
+  use mod1
+  real :: s
+  ncells = 2
+  call sub (s)
+  if (int (s) .ne. ncells) stop 1
+  ncells = 10
+  call sub (s)
+  if (int (s) .ne. ncells) stop 2
+end
+