https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110360
Bug ID: 110360
Summary: ABI issue with character,value dummy argument
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: anlauf at gcc dot gnu.org
Target Milestone: ---
Consider:
program p
implicit none
integer :: a = 65
call val (char(65)) ! OK
call val (char(a)) ! random junk
contains
subroutine val (c)
character, value :: c
print *, "by value: ", c
end
end
This should print twice
by value: A
by value: A
but the second line contains junk, as the tree-dump shows:
static void val (character(kind=1)[1:1], integer(kind=8));
static integer(kind=4) a = 65;
val ("A", 1);
{
character(kind=1) char.1;
char.1 = (character(kind=1)) a;
val (&char.1, 1);
}
Clearly, the second case is inconsistent with the ABI, see the prototype, and
https://gcc.gnu.org/onlinedocs/gfortran/Argument-passing-conventions.html
The ABI does not (yet) state how to handle character of length > 1 or variable
length - we'll likely need to pass a pointer to a temporary - but as long as
the dummy has fixed length 1 we should pass the argument by value.
A related issue occurs for actual arguments that are allocatable scalars
(or pointers to scalars).