[committed] PR fortran/95500 - Segfault compiling extra interface on intrinsic

Message ID trinity-122da2d4-3b77-4a52-b55d-1c7f1a2c939e-1591297576822@3c-app-gmx-bs48
State New
Headers show
Series
  • [committed] PR fortran/95500 - Segfault compiling extra interface on intrinsic
Related show

Commit Message

Harald Anlauf June 4, 2020, 7:06 p.m.
Committed as obvious.  Regtests cleanly on x86_64-pc-linux-gnu.

Thanks to Steve Kargl for the patch.

This is an ICE-on-valid due to a NULL pointer dereference;
it looks safe and could be backported to 9/10.

Thanks,
Harald


PR fortran/95500 - Segfault compiling extra interface on intrinsic

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.

Patch

diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 435eaeb2c99..8b2afd27fb3 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -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
index 00000000000..e9eb7c65c86
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr95500.f90
@@ -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