PR fortran/95500 - Segfault compiling extra interface on intrinsic
authorHarald Anlauf <anlauf@gmx.de>
Thu, 4 Jun 2020 19:00:33 +0000 (21:00 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Thu, 4 Jun 2020 19:01:26 +0000 (21:01 +0200)
Converting an expression so that it can be passed by reference could
result in a NULL pointer dereference.

2020-06-04  Steven G. Kargl  <kargl@gcc.gnu.org>
    Harald Anlauf  <anlauf@gmx.de>

gcc/fortran/
PR fortran/95500
* trans-expr.c (gfc_conv_expr_reference): Do not dereference NULL
pointer.

gcc/testsuite/
PR fortran/95500
* gfortran.dg/pr95500.f90: New test.

gcc/fortran/trans-expr.c
gcc/testsuite/gfortran.dg/pr95500.f90 [new file with mode: 0644]

index 435eaeb2c992dc605fc976692fd28979506518e4..8b2afd27fb3812e277ad930ece89c83f80ef66b2 100644 (file)
@@ -8811,6 +8811,7 @@ gfc_conv_expr_reference (gfc_se * se, gfc_expr * expr, bool add_clobber)
 
   if (expr->expr_type == EXPR_FUNCTION
       && ((expr->value.function.esym
+          && expr->value.function.esym->result
           && expr->value.function.esym->result->attr.pointer
           && !expr->value.function.esym->result->attr.dimension)
          || (!expr->value.function.esym && !expr->ref
diff --git a/gcc/testsuite/gfortran.dg/pr95500.f90 b/gcc/testsuite/gfortran.dg/pr95500.f90
new file mode 100644 (file)
index 0000000..e9eb7c6
--- /dev/null
@@ -0,0 +1,15 @@
+! { dg-do compile }
+! PR fortran/95500 - ICE compiling extra interface on intrinsic
+
+program test_intrinsic
+  implicit none
+  intrinsic :: alog
+  intrinsic :: dlog
+  real (4), parameter :: one = 1
+
+  interface ln
+     procedure :: alog, dlog
+  end interface ln
+
+  write (*,*) 'ln  1', ln (one)
+end program test_intrinsic