https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105012

--- Comment #17 from anlauf at gcc dot gnu.org ---
(In reply to Richard Biener from comment #11)
> (In reply to Richard Biener from comment #10)
> > likely triggered by the INTENT(out), it looks like gfortran fails to 
> > properly
> > name-lookup a variable of the same name as the function?  The intent is
> > likely
> > to have the return value assigned by CALERF_r8.  So it also looks like
> > gfortran miscompiles such testcase.
[...]
> SUBROUTINE Y (Z)
>       real(8), intent(out) :: Z
>       Z = 1.
> END SUBROUTINE Y
> FUNCTION X()
>       real(8) :: X
>       CALL Y (X)
> END FUNCTION X
> PROGRAM TEST
>     real(8) :: Z
>     Z = X();
>     if (Z.ne.1.) STOP 1
> END PROGRAM
> 
> but still
> 
> t.f90:11:9:
> 
>    11 |     Z = X();
>       |         1
> Error: Return type mismatch of function 'x' at (1) (REAL(4)/REAL(8))

The error message is correct.  The main program is missing a decl that
X is real(8) not real(4).  E.g. adding

  real(8) :: X

resolves the type mismatch.

(Replacing 1. by 1._8 also eliminates some conversions in the dump.)

The dummy argument Z of Y is marked as intent(out):

Namespace: A-H: (REAL 4) I-N: (INTEGER 4) O-Z: (REAL 4)
procedure name = y
  symtree: 'y'           || symbol: 'y'            
    type spec : (UNKNOWN 0)
    attributes: (PROCEDURE  SUBROUTINE)
    Formal arglist: z
  symtree: 'z'           || symbol: 'z'            
    type spec : (REAL 8)
    attributes: (VARIABLE  DUMMY(OUT))

A quick glance at trans-expr.cc::gfc_conv_procedure_call suggests that
the logic that determines whether to generate a clobber depends on the
properties of the formal argument being available.

6505                          bool add_clobber;
6506                          add_clobber = fsym && fsym->attr.intent ==
INTENT_OUT
6507                            && !fsym->attr.allocatable &&
!fsym->attr.pointer
6508                            && e->symtree && e->symtree->n.sym
6509                            && !e->symtree->n.sym->attr.dimension
6510                            && !e->symtree->n.sym->attr.pointer
6511                            && !e->symtree->n.sym->attr.allocatable
6512                            /* See PR 41453.  */
6513                            && !e->symtree->n.sym->attr.dummy
6514                            /* FIXME - PR 87395 and PR 41453  */
6515                            && e->symtree->n.sym->attr.save == SAVE_NONE
6516                            && !e->symtree->n.sym->attr.associate_var
6517                            && e->ts.type != BT_CHARACTER && e->ts.type !=
BT_DERIVED
6518                            && e->ts.type != BT_CLASS &&
!sym->attr.elemental;
6519
6520                          gfc_conv_expr_reference (&parmse, e,
add_clobber);
(gdb) p fsym
$7 = (gfc_symbol *) 0x0

Without an explicit interface, stone-age-style code is not supported here yet.

Reply via email to