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

--- Comment #22 from anlauf at gcc dot gnu.org ---
(In reply to Richard Biener from comment #20)
> With your patch I still see
> 
> __attribute__((fn spec (". r ")))
> real(kind=8) derfc (real(kind=8) & restrict x)
> {
>   integer(kind=4) jint;
>   real(kind=8) __result_derfc;
> 
>   derfc = {CLOBBER};
>   calerf_r8 ((real(kind=8) *) x, &__result_derfc, &jint);
>   return __result_derfc;
> 
> 
> I think the patch wouldn't adjust what the clobber is added to but only
> whether it is added, but it seems it fails to catch this case?  So maybe
> the error is elsewhere.

It appears that there are two (only weakly dependent) issues at play here:

1) The patch in comment#18 addresses only the case when the procedures are
   outside of a module, so that the frontend does not see their interfaces.
   But since we nowadays have a more global view of all procedures in a file,
   we are in principle able to exploit things like attributes of the dummies.

2) For the handling of clobber for variables that are associated with
   INTENT(OUT) dummy arguments see also PR41453, which is still open due
   to some corner cases not yet addressed.  The present case, where the
   actual argument is the function result, shows an anomaly:
   The clobber is fine if the function has an explicit result clause,
   while we are confusing symbols (x vs. __result_x) when there is no
   result clause.

   See PR41453#c8 for details.

The remaining problem from PR41453#c8 is the following code in trans-expr.cc:

(gdb) l 9539,9548
9539          else if (add_clobber && expr->ref == NULL)
9540            {
9541              tree clobber;
9542              tree var;
9543              /* FIXME: This fails if var is passed by reference, see PR
9544                 41453.  */
9545              var = expr->symtree->n.sym->backend_decl;
9546              clobber = build_clobber (TREE_TYPE (var));
9547              gfc_add_modify (&se->pre, var, clobber);
9548            }

One needs to understand how to fix up 'var' here for the case at hand.

> Note with my testcase from comment#11 fixed as you suggest I don't see a
> clobber
> at all - I probably simplified too much and gfortran needs the wrapped module
> to see the intent(out).

I thought to have fixed that one...

Reply via email to