+2020-05-05 Steve Kargl <kargl@gcc.gnu.org>
+ Harald Anlauf <anlauf@gmx.de>
+
+ PR fortran/93366
+ * check.c (gfc_check_associated, invalid_null_arg): Factorize
+ check for presence of invalid NULL() argument.
+ (gfc_check_kind, gfc_check_merge, gfc_check_shape)
+ (gfc_check_sizeof, gfc_check_spread, gfc_check_transfer): Use this
+ check for presence of invalid NULL() arguments.
+
2020-04-29 Stefan Schulze Frielinghaus <stefansf@linux.ibm.com>
PR fortran/94769
return true;
}
+static bool
+invalid_null_arg (gfc_expr *x)
+{
+ if (x->expr_type == EXPR_NULL)
+ {
+ gfc_error ("NULL at %L is not permitted as actual argument "
+ "to %qs intrinsic function", &x->where,
+ gfc_current_intrinsic);
+ return true;
+ }
+ return false;
+}
bool
gfc_check_associated (gfc_expr *pointer, gfc_expr *target)
symbol_attribute attr1, attr2;
int i;
bool t;
- locus *where;
- where = &pointer->where;
-
- if (pointer->expr_type == EXPR_NULL)
- goto null_arg;
+ if (invalid_null_arg (pointer))
+ return false;
attr1 = gfc_expr_attr (pointer);
if (target == NULL)
return true;
- where = &target->where;
- if (target->expr_type == EXPR_NULL)
- goto null_arg;
+ if (invalid_null_arg (target))
+ return false;
if (target->expr_type == EXPR_VARIABLE || target->expr_type == EXPR_FUNCTION)
attr2 = gfc_expr_attr (target);
}
}
return t;
-
-null_arg:
-
- gfc_error ("NULL pointer at %L is not permitted as actual argument "
- "of %qs intrinsic function", where, gfc_current_intrinsic);
- return false;
-
}
bool
gfc_check_kind (gfc_expr *x)
{
+ if (invalid_null_arg (x))
+ return false;
+
if (gfc_bt_struct (x->ts.type) || x->ts.type == BT_CLASS)
{
gfc_error ("%qs argument of %qs intrinsic at %L must be of "
bool
gfc_check_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask)
{
+ if (invalid_null_arg (tsource))
+ return false;
+
+ if (invalid_null_arg (fsource))
+ return false;
+
if (!same_type_check (tsource, 0, fsource, 1))
return false;
{
gfc_array_ref *ar;
+ if (invalid_null_arg (source))
+ return false;
+
if (source->rank == 0 || source->expr_type != EXPR_VARIABLE)
return true;
bool
gfc_check_sizeof (gfc_expr *arg)
{
+ if (invalid_null_arg (arg))
+ return false;
+
if (arg->ts.type == BT_PROCEDURE)
{
gfc_error ("%qs argument of %qs intrinsic at %L shall not be a procedure",
bool
gfc_check_spread (gfc_expr *source, gfc_expr *dim, gfc_expr *ncopies)
{
+ if (invalid_null_arg (source))
+ return false;
+
if (source->rank >= GFC_MAX_DIMENSIONS)
{
gfc_error ("%qs argument of %qs intrinsic at %L must be less "
size_t source_size;
size_t result_size;
+ if (invalid_null_arg (source))
+ return false;
+
/* SOURCE shall be a scalar or array of any type. */
if (source->ts.type == BT_PROCEDURE
&& source->symtree->n.sym->attr.subroutine == 1)
if (mold->ts.type == BT_BOZ && illegal_boz_arg (mold))
return false;
+ if (invalid_null_arg (mold))
+ return false;
+
/* MOLD shall be a scalar or array of any type. */
if (mold->ts.type == BT_PROCEDURE
&& mold->symtree->n.sym->attr.subroutine == 1)
--- /dev/null
+! { dg-do compile }
+!
+! PR fortran/93366 - ICE on invalid, reject invalid use of NULL() as argument
+
+program p
+ print *, kind (null()) ! { dg-error "NULL at" }
+ print *, [ merge(null(), [1] ,.true.) ] ! { dg-error "NULL at" }
+ print *, [ merge([1] , null(),.true.) ] ! { dg-error "NULL at" }
+ print *, [ merge(null(), null(),.true.) ] ! { dg-error "NULL at" }
+ print *, shape (null()) ! { dg-error "NULL at" }
+ print *, sizeof (null()) ! { dg-error "NULL at" }
+ print *, spread (null(),1,1) ! { dg-error "NULL at" }
+ print *, transfer ( 1 , null()) ! { dg-error "NULL at" }
+ print *, transfer ([1], null()) ! { dg-error "NULL at" }
+ print *, transfer (null(), 1) ! { dg-error "NULL at" }
+ print *, transfer (null(), [1]) ! { dg-error "NULL at" }
+ print *, transfer (null(), null()) ! { dg-error "NULL at" }
+end