[gcc r13-3342] Fortran: NULL pointer dereference in gfc_simplify_image_index [PR104330]
Harald Anlauf
anlauf@gcc.gnu.org
Mon Oct 17 20:47:20 GMT 2022
https://gcc.gnu.org/g:84807af0ca6dfdb81abb8e925ce32acbcab29868
commit r13-3342-g84807af0ca6dfdb81abb8e925ce32acbcab29868
Author: Steve Kargl <kargl@gcc.gnu.org>
Date: Mon Oct 17 22:42:40 2022 +0200
Fortran: NULL pointer dereference in gfc_simplify_image_index [PR104330]
gcc/fortran/ChangeLog:
PR fortran/104330
* simplify.cc (gfc_simplify_image_index): Do not dereference NULL
pointer.
gcc/testsuite/ChangeLog:
PR fortran/104330
* gfortran.dg/pr104330.f90: New test.
Diff:
---
gcc/fortran/simplify.cc | 2 +-
gcc/testsuite/gfortran.dg/pr104330.f90 | 20 ++++++++++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc
index 6ac92cf9db8..9c2fea8c5f2 100644
--- a/gcc/fortran/simplify.cc
+++ b/gcc/fortran/simplify.cc
@@ -8266,7 +8266,7 @@ gfc_simplify_image_index (gfc_expr *coarray, gfc_expr *sub)
if (ref->type == REF_COMPONENT)
as = ref->u.ar.as;
- if (as->type == AS_DEFERRED)
+ if (!as || as->type == AS_DEFERRED)
return NULL;
/* "valid sequence of cosubscripts" are required; thus, return 0 unless
diff --git a/gcc/testsuite/gfortran.dg/pr104330.f90 b/gcc/testsuite/gfortran.dg/pr104330.f90
new file mode 100644
index 00000000000..9ff48e2f6cc
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr104330.f90
@@ -0,0 +1,20 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=lib" }
+!
+! PR fortran/104330 - ICE in gfc_simplify_image_index
+! Contributed by G.Steinmetz
+
+program p
+ implicit none
+ type t
+ end type t
+ class(*), allocatable :: x[:]
+ class(t), allocatable :: y[:]
+ type(t), allocatable :: z[:]
+ allocate (real :: x[*])
+ print *, image_index(x, [1])
+ allocate (t :: y[*])
+ print *, image_index(y, [1])
+ allocate (t :: z[*])
+ print *, image_index(z, [1])
+end
More information about the Gcc-cvs
mailing list