[Bug fortran/107266] Reject kind=4 characters for BIND(C) – it invalid and generates wrong code
kargl at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Oct 14 18:51:22 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107266
--- Comment #3 from kargl at gcc dot gnu.org ---
(In reply to kargl from comment #2)
> (In reply to Tobias Burnus from comment #1)
> > Better example:
> >
> > character(kind=4) function f(x) bind(C)
> > character(kind=4), value :: x
> > end
> >
> >
> > Has the dump:
> >
> > __attribute__((fn spec (". w ")))
> > character(kind=1) f (character(kind=1) x)
> > {
> > (void) 0;
> > }
> >
> >
> > Note the change to kind=1
>
> So, you want gfortran to reject the function.
>
> It gets real ugly with
>
> function f(x) bind(C) result(a)
> character(kind=4) a
> character(kind=4), value :: x
> a = x
> end
>
> leading to
>
> __attribute__((fn spec (". w ")))
> character(kind=1) f (character(kind=1) x)
> {
> character(kind=1) a;
>
> *(character(kind=4) *) &a = *(character(kind=4) *) &x;
> return a;
> }
Looks like resolve.cc:resolve_symbol() might be able to dela with this.
For my function with the result variable one has
(gdb) p *sym
$4 = {name = 0x2041ec100 "f", module = 0x0, declared_at = {
nextc = 0x203a38160, lb = 0x203a38140}, ts = {type = BT_UNKNOWN, kind = 0,
...
in_equivalence = 0, function = 1, subroutine = 0, procedure = 0,
generic = 0, generic_copy = 0, implicit_type = 0, untyped = 0,
is_bind_c = 1, extension = 0, is_class = 0, class_ok = 0, vtab = 0,
...
value = 0x0, as = 0x0, result = 0x203a57600, components = 0x0,
(gdb) p *sym->result
$5 = {name = 0x2041ec110 "a", module = 0x0, declared_at = {
nextc = 0x203a381dc, lb = 0x203a38140}, ts = {type = BT_CHARACTER,
kind = 4, u = {derived = 0x203a245a0, cl = 0x203a245a0, pad = 60966304},
...
dummy = 0, result = 1, assign = 0, threadprivate = 0,
so gfortran can check for kind=4 versus kind=1 (aka C_CHAR).
More information about the Gcc-bugs
mailing list