https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110825
Bug ID: 110825 Summary: TYPE(*) dummy argument to generate an unused hidden argument Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: kargl at gcc dot gnu.org Target Milestone: --- The was pointed out in Fortran Discourse, https://fortran-lang.discourse.group/t/strange-behaviour-when-using-type-and-character-in-gfortran/6233 that gfortran generates wrong code for a valid program. Here's a slightly modified version of the program. program foo implicit none character(100) :: not_used call sub(not_used, "123") contains subroutine sub(useless_var, print_this) type(*), intent(in) :: useless_var character(*), intent(in) :: print_this if (len_trim(print_this) /= 3) stop 1 end subroutine sub end The subroutine reference in the main program is generating a call with two hidden arguments. From -fdump-tree-original, void MAIN__ () { static void sub (void * & restrict, character(kind=1)[1:] & restrict, integer(kind=8)); character(kind=1) not_used[1:100]; sub (¬_used, &"123"[1]{lb: 1 sz: 1}, 100, 3); } we have hidden arguments 100 and 3. However, the code generated for the contained subroutine is only expecting one hidden argument. __attribute__((fn spec (". r r "))) void sub (void * & restrict useless_var, character(kind=1)[1:_print_this] & restrict print_this, integer(kind=8) _print_this) { ... } Thus, when compiled and executed the program hits 'STOP 1'. Likely, gfortran needs to add a possibly unused hidden argument to the argument list for a TYPE(*) dummy argument.