/* Pointers to the parameter specification being used. */
gfc_actual_arglist *actual_param;
gfc_actual_arglist *tail = NULL;
- /* Used to build up the name of the PDT instance. The prefix uses 4
+ /* Used to build up the name of the PDT instance. The prefix uses 3
characters and each KIND parameter 2 more. Allow 8 of the latter. */
- char name[GFC_MAX_SYMBOL_LEN + 21];
-
+ char name[GFC_MAX_SYMBOL_LEN + PDT_PREFIX_LEN + 16];
bool name_seen = (param_list == NULL);
bool assumed_seen = false;
bool deferred_seen = false;
type_param_name_list = pdt->formal;
actual_param = param_list;
- sprintf (name, "Pdt%s", pdt->name);
+ sprintf (name, "%s%s", PDT_PREFIX, pdt->name);
/* Prevent a PDT component of the same type as the template from being
converted into an instance. Doing this results in the component being
(expr && expr->expr_type == EXPR_VARIABLE \
&& expr->symtree->n.sym->assoc \
&& expr->symtree->n.sym->assoc->inferred_type)
+#define PDT_PREFIX "PDT"
+#define PDT_PREFIX_LEN 3
#define IS_PDT(sym) \
(sym != NULL && sym->ts.type == BT_DERIVED \
&& sym->ts.u.derived \
/* Include pdt_types if their associated pdt_template is in a
USE, ONLY list. */
if (p == NULL && name[0] == 'P'
- && startswith (name, "Pdt")
+ && startswith (name, PDT_PREFIX)
&& module_list)
{
gfc_use_list *ml = module_list;
for (; ml; ml = ml->next)
if (ml->rename
- && !strncmp (&name[3], ml->rename->use_name,
+ && !strncmp (&name[PDT_PREFIX_LEN],
+ ml->rename->use_name,
strlen (ml->rename->use_name)))
p = name;
}
goto error;
}
- if (resolve_bindings_derived->attr.pdt_template
- && gfc_pdt_is_instance_of (resolve_bindings_derived,
- CLASS_DATA (me_arg)->ts.u.derived)
+ if (((resolve_bindings_derived->attr.pdt_template
+ && gfc_pdt_is_instance_of (resolve_bindings_derived,
+ CLASS_DATA (me_arg)->ts.u.derived))
+ || resolve_bindings_derived->attr.pdt_type)
&& (me_arg->param_list != NULL)
&& (gfc_spec_list_type (me_arg->param_list,
CLASS_DATA(me_arg)->ts.u.derived)
gfc_symbol *t2 -> pdt instance to be verified.
In decl.cc, gfc_get_pdt_instance, a pdt instance is given a 3 character
- prefix "Pdt", followed by an underscore list of the kind parameters,
+ prefix PDT_PREFIX, followed by an underscore list of the kind parameters,
up to a maximum of 8 kind parameters. To verify if a PDT Type corresponds
to the template, this functions extracts t2's derive_type name,
and compares it to the derive_type name of t1 for compatibility.
For example:
- t2->name = Pdtf_2_2; extract out the 'f' and compare with t1->name. */
+ t2->name = PDT_PREFIXf_2_2; extract the 'f' and compare with t1->name. */
bool
gfc_pdt_is_instance_of (gfc_symbol *t1, gfc_symbol *t2)
return false;
/* Limit comparison to length of t1->name to ignore new kind params. */
- if ( !(strncmp (&(t2->name[3]), t1->name, strlen (t1->name)) == 0) )
+ if ( !(strncmp (&(t2->name[PDT_PREFIX_LEN]), t1->name,
+ strlen (t1->name)) == 0) )
return false;
return true;
if (int (pop_8 (root)) .ne. 0) STOP 4
end subroutine
end program ch2701
-! { dg-final { scan-tree-dump-times "Pdtlink_8._deallocate " 5 "original" } }
+! { dg-final { scan-tree-dump-times "PDTlink_8._deallocate " 5 "original" } }
! { dg-final { scan-tree-dump-times ".n.data = 0B" 9 "original" } }
! { dg-final { scan-tree-dump-times "__builtin_free" 15 "original" } }
print *, kind (z%x%n), z%x%n
end subroutine
end
-! { dg-final { scan-tree-dump-times "Pdtt2_4.1.x.n = 8" 1 "original" } }
-! { dg-final { scan-tree-dump-times "z = Pdtt2_4.1" 1 "original" } }
+! { dg-final { scan-tree-dump-times "PDTt2_4.1.x.n = 8" 1 "original" } }
+! { dg-final { scan-tree-dump-times "z = PDTt2_4.1" 1 "original" } }
end subroutine ! { dg-warning ".mapped_tensor. is used uninitialized" }
end
-! { dg-final { scan-tree-dump-times "Pdttensor_t_4.2.j = 42" 1 "original" } }
-! { dg-final { scan-tree-dump-times "struct Pdttensor_t_4 mt" 1 "original" } }
+! { dg-final { scan-tree-dump-times "PDTtensor_t_4.2.j = 42" 1 "original" } }
+! { dg-final { scan-tree-dump-times "struct PDTtensor_t_4 mt" 1 "original" } }
--- /dev/null
+! { dg-do compile }
+!
+! Test the fix for PR108663
+!
+! Contributed by
+!
+module m
+ type t(n)
+ integer, len :: n
+ integer :: a(n)
+ end type
+contains
+ subroutine s(x, arr)
+ type(t(2)) :: x
+ integer :: arr(2)
+ if (any (x%a /= arr)) stop 1
+ end
+end
+program p
+ use m, only: t, pdtt, s ! { dg-error "not found in module" }
+
+ type(t(2)) :: y = t(2)([1,2])
+ type (pdtt) :: z ! { dg-error "being used before it is defined" }
+
+ call s(y, [1,2])
+ y = t(2)([3,4])
+ call s(y, [3,4])
+end