aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/decl.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/fortran/decl.c')
-rw-r--r--gcc/fortran/decl.c128
1 files changed, 117 insertions, 11 deletions
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 947e4f8..f2e8896 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -1551,21 +1551,109 @@ gfc_verify_c_interop_param (gfc_symbol *sym)
sym->ns->proc_name->name);
}
+ /* Per F2018, 18.3.6 (5), pointer + contiguous is not permitted. */
+ if (sym->attr.pointer && sym->attr.contiguous)
+ gfc_error ("Dummy argument %qs at %L may not be a pointer with "
+ "CONTIGUOUS attribute as procedure %qs is BIND(C)",
+ sym->name, &sym->declared_at, sym->ns->proc_name->name);
+
/* Character strings are only C interoperable if they have a
- length of 1. */
- if (sym->ts.type == BT_CHARACTER && !sym->attr.dimension)
+ length of 1. However, as an argument they are also iteroperable
+ when passed as descriptor (which requires len=: or len=*). */
+ if (sym->ts.type == BT_CHARACTER)
{
gfc_charlen *cl = sym->ts.u.cl;
- if (!cl || !cl->length || cl->length->expr_type != EXPR_CONSTANT
- || mpz_cmp_si (cl->length->value.integer, 1) != 0)
+
+ if (sym->attr.allocatable || sym->attr.pointer)
{
- gfc_error ("Character argument %qs at %L "
- "must be length 1 because "
- "procedure %qs is BIND(C)",
- sym->name, &sym->declared_at,
- sym->ns->proc_name->name);
+ /* F2018, 18.3.6 (6). */
+ if (!sym->ts.deferred)
+ {
+ if (sym->attr.allocatable)
+ gfc_error ("Allocatable character dummy argument %qs "
+ "at %L must have deferred length as "
+ "procedure %qs is BIND(C)", sym->name,
+ &sym->declared_at, sym->ns->proc_name->name);
+ else
+ gfc_error ("Pointer character dummy argument %qs at %L "
+ "must have deferred length as procedure %qs "
+ "is BIND(C)", sym->name, &sym->declared_at,
+ sym->ns->proc_name->name);
+ retval = false;
+ }
+ else if (!gfc_notify_std (GFC_STD_F2018,
+ "Deferred-length character dummy "
+ "argument %qs at %L of procedure "
+ "%qs with BIND(C) attribute",
+ sym->name, &sym->declared_at,
+ sym->ns->proc_name->name))
+ retval = false;
+ else if (!sym->attr.dimension)
+ {
+ /* FIXME: Use CFI array descriptor for scalars. */
+ gfc_error ("Sorry, deferred-length scalar character dummy "
+ "argument %qs at %L of procedure %qs with "
+ "BIND(C) not yet supported", sym->name,
+ &sym->declared_at, sym->ns->proc_name->name);
+ retval = false;
+ }
+ }
+ else if (sym->attr.value
+ && (!cl || !cl->length
+ || cl->length->expr_type != EXPR_CONSTANT
+ || mpz_cmp_si (cl->length->value.integer, 1) != 0))
+ {
+ gfc_error ("Character dummy argument %qs at %L must be "
+ "of length 1 as it has the VALUE attribute",
+ sym->name, &sym->declared_at);
retval = false;
}
+ else if (!cl || !cl->length)
+ {
+ /* Assumed length; F2018, 18.3.6 (5)(2).
+ Uses the CFI array descriptor - also for scalars and
+ explicit-size/assumed-size arrays. */
+ if (!gfc_notify_std (GFC_STD_F2018,
+ "Assumed-length character dummy argument "
+ "%qs at %L of procedure %qs with BIND(C) "
+ "attribute", sym->name, &sym->declared_at,
+ sym->ns->proc_name->name))
+ retval = false;
+ else if (!sym->attr.dimension
+ || sym->as->type == AS_ASSUMED_SIZE
+ || sym->as->type == AS_EXPLICIT)
+ {
+ /* FIXME: Valid - should use the CFI array descriptor, but
+ not yet handled for scalars and assumed-/explicit-size
+ arrays. */
+ gfc_error ("Sorry, character dummy argument %qs at %L "
+ "with assumed length is not yet supported for "
+ "procedure %qs with BIND(C) attribute",
+ sym->name, &sym->declared_at,
+ sym->ns->proc_name->name);
+ retval = false;
+ }
+ }
+ else if (cl->length->expr_type != EXPR_CONSTANT
+ || mpz_cmp_si (cl->length->value.integer, 1) != 0)
+ {
+ /* F2018, 18.3.6, (5), item 4. */
+ if (!sym->attr.dimension
+ || sym->as->type == AS_ASSUMED_SIZE
+ || sym->as->type == AS_EXPLICIT)
+ {
+ gfc_error ("Character dummy argument %qs at %L must be "
+ "of constant length of one or assumed length, "
+ "unless it has assumed shape or assumed rank, "
+ "as procedure %qs has the BIND(C) attribute",
+ sym->name, &sym->declared_at,
+ sym->ns->proc_name->name);
+ retval = false;
+ }
+ /* else: valid only since F2018 - and an assumed-shape/rank
+ array; however, gfc_notify_std is already called when
+ those array types are used. Thus, silently accept F200x. */
+ }
}
/* We have to make sure that any param to a bind(c) routine does
@@ -2081,6 +2169,24 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus)
sym->as->type = AS_EXPLICIT;
}
+ /* Ensure that explicit bounds are simplified. */
+ if (sym->attr.flavor == FL_PARAMETER && sym->attr.dimension
+ && sym->as->type == AS_EXPLICIT)
+ {
+ for (int dim = 0; dim < sym->as->rank; ++dim)
+ {
+ gfc_expr *e;
+
+ e = sym->as->lower[dim];
+ if (e->expr_type != EXPR_CONSTANT)
+ gfc_reduce_init_expr (e);
+
+ e = sym->as->upper[dim];
+ if (e->expr_type != EXPR_CONSTANT)
+ gfc_reduce_init_expr (e);
+ }
+ }
+
/* Need to check if the expression we initialized this
to was one of the iso_c_binding named constants. If so,
and we're a parameter (constant), let it be iso_c.
@@ -2721,7 +2827,7 @@ variable_decl (int elem)
}
/* %FILL components may not have initializers. */
- if (gfc_str_startswith (name, "%FILL") && gfc_match_eos () != MATCH_YES)
+ if (startswith (name, "%FILL") && gfc_match_eos () != MATCH_YES)
{
gfc_error ("%qs entity cannot have an initializer at %C", "%FILL");
m = MATCH_ERROR;
@@ -8221,7 +8327,7 @@ gfc_match_end (gfc_statement *st)
{
case COMP_ASSOCIATE:
case COMP_BLOCK:
- if (gfc_str_startswith (block_name, "block@"))
+ if (startswith (block_name, "block@"))
block_name = NULL;
break;