IDENTIFIER_POINTER (gfc_sym_mangled_identifier (sym))));
token = build_decl (DECL_SOURCE_LOCATION (decl), VAR_DECL, token_name,
token_type);
- if (sym->attr.use_assoc)
+ if (sym->attr.use_assoc
+ || (sym->attr.host_assoc && sym->attr.used_in_submodule))
DECL_EXTERNAL (token) = 1;
else
TREE_STATIC (token) = 1;
if (sym->module && !sym->attr.use_assoc)
{
+ module_htab_entry *mod
+ = cur_module ? cur_module : gfc_find_module (sym->module);
pushdecl (token);
DECL_CONTEXT (token) = sym->ns->proc_name->backend_decl;
- gfc_module_add_decl (cur_module, token);
+ gfc_module_add_decl (mod, token);
}
else if (sym->attr.host_assoc
&& TREE_CODE (DECL_CONTEXT (current_function_decl))
--- /dev/null
+! This test belongs to submodule_1.f90
+! It is references as additional source in that test.
+! The two code fragments need to be in separate files to show
+! the error of pr80235.
+
+submodule (pr80235) pr80235_sub
+
+contains
+ module subroutine test()
+ implicit none
+ if (var%v /= 42) stop 1
+ end subroutine
+end submodule pr80235_sub
+
+program pr80235_prg
+ use pr80235
+
+ implicit none
+
+ var%v = 42
+ call test()
+end program
--- /dev/null
+!{ dg-do run }
+!{ dg-additional-sources add_sources/submodule_1_sub.f90 }
+
+! Separating the module and the submodule is needed to show the error.
+! Having all code pieces in one file does not show the error.
+
+module pr80235
+ implicit none
+
+ private
+ public :: test, var
+
+ type T
+ integer :: v
+ end type T
+
+interface
+
+ module subroutine test()
+ end subroutine
+
+end interface
+
+ type(T) :: var[*]
+
+end module pr80235
+
+
+