diff options
author | Harald Anlauf <anlauf@gmx.de> | 2022-03-29 23:33:23 +0200 |
---|---|---|
committer | Harald Anlauf <anlauf@gmx.de> | 2022-04-05 19:39:14 +0200 |
commit | 892c7f03ae63121766a8be48f7e3b672547fd627 (patch) | |
tree | ea611981cfa383b5b393604075afebac00e865f1 /gcc | |
parent | d46685b04071a485b56de353d997a866bfc8caba (diff) | |
download | gcc-892c7f03ae63121766a8be48f7e3b672547fd627.zip gcc-892c7f03ae63121766a8be48f7e3b672547fd627.tar.gz gcc-892c7f03ae63121766a8be48f7e3b672547fd627.tar.bz2 |
Fortran: improve error recovery for invalid coarray function declarations
gcc/fortran/ChangeLog:
PR fortran/104210
* arith.cc (eval_intrinsic): Avoid NULL pointer dereference.
(gfc_zero_size_array): Likewise.
gcc/testsuite/ChangeLog:
PR fortran/104210
* gfortran.dg/pr104210.f90: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/fortran/arith.cc | 9 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/pr104210.f90 | 15 |
2 files changed, 21 insertions, 3 deletions
diff --git a/gcc/fortran/arith.cc b/gcc/fortran/arith.cc index 06e032e..d57059a 100644 --- a/gcc/fortran/arith.cc +++ b/gcc/fortran/arith.cc @@ -1489,6 +1489,9 @@ eval_intrinsic (gfc_intrinsic_op op, int unary; arith rc; + if (!op1) + return NULL; + gfc_clear_ts (&temp.ts); switch (op) @@ -1703,11 +1706,11 @@ eval_type_intrinsic0 (gfc_intrinsic_op iop, gfc_expr *op) /* Return nonzero if the expression is a zero size array. */ -static int +static bool gfc_zero_size_array (gfc_expr *e) { - if (e->expr_type != EXPR_ARRAY) - return 0; + if (e == NULL || e->expr_type != EXPR_ARRAY) + return false; return e->value.constructor == NULL; } diff --git a/gcc/testsuite/gfortran.dg/pr104210.f90 b/gcc/testsuite/gfortran.dg/pr104210.f90 new file mode 100644 index 0000000..182404c --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr104210.f90 @@ -0,0 +1,15 @@ +! { dg-do compile } +! { dg-options "-fcoarray=single" } +! PR fortran/104210 +! Contributed by G.Steinmetz + +function f() ! { dg-error "shall not be a coarray" } + integer :: f[*] +end +program p + interface + function f() ! { dg-error "shall not be a coarray" } + integer :: f[*] + end + end interface +end |