Invalid data initializations
Steve Kargl
sgk@troutmask.apl.washington.edu
Sun Jul 10 17:51:00 GMT 2016
leads to an executable that segfaults.
program a
integer, pointer :: i
data i /42/
print *, i
end program a
or
program a
integer, target :: k
integer, pointer :: i => k ! Invalid but accepted!
data i /42/ ! Invalid
print *, i
end program a
Second error message doesn't trigger with
program a
integer, target :: k
integer, pointer :: i
data i /k/
print *, i
end program a
Index: data.c
===================================================================
--- data.c (revision 238178)
+++ data.c (working copy)
@@ -506,6 +515,35 @@ gfc_assign_data_value (gfc_expr *lvalue,
}
expr = gfc_copy_expr (rvalue);
+
+ if (symbol->attr.pointer && expr->expr_type == EXPR_CONSTANT)
+ {
+ if (gfc_option.allow_std & GFC_STD_F2008)
+ gfc_error("data-stmt-constant at %L shall be null-init "
+ "or initial-data-target "
+ "if and only if the corresponding "
+ "data-stmt-object has the POINTER attribute",
+ &expr->where);
+ else
+ gfc_error("data-stmt-constant at %L shall be null-init "
+ "if and only if the corresponding "
+ "data-stmt-object has the POINTER attribute",
+ &expr->where);
+ return false;
+ }
+
+ if (gfc_option.allow_std & GFC_STD_F2008
+ && symbol->attr.pointer
+ && !(expr->symtree->n.sym->attr.save
+ && expr->symtree->n.sym->attr.target))
+ {
+ if (gfc_option.allow_std & GFC_STD_F2008)
+ gfc_error("initial-data-target at %L requires the TARGET and "
+ "SAVE attributes", &expr->where);
+ return false;
+ }
+
+
if (!gfc_compare_types (&lvalue->ts, &expr->ts))
gfc_convert_type (expr, &lvalue->ts, 0);
}
--
Steve
More information about the Fortran
mailing list