[Bug middle-end/41453] use INTENT(out) for optimization
anlauf at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Aug 25 19:31:56 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41453
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |anlauf at gcc dot gnu.org
--- Comment #8 from anlauf at gcc dot gnu.org ---
Sometimes we now generate a clobber for the wrong variable when a function
result is involved. An example, derived from PR105012:
! compile with -fdump-tree-original
module m
contains
SUBROUTINE Y (Z)
real, intent(out) :: Z
Z = 1.
END SUBROUTINE Y
FUNCTION X ()
real :: X
CALL Y (X) ! direct use of function result, bad clobber
END FUNCTION X
FUNCTION F () result(res)
real :: res
CALL Y (res) ! using explicit result variable, good clobber
END FUNCTION F
end
With current trunk this produces:
__attribute__((fn spec (". ")))
real(kind=4) f ()
{
real(kind=4) res;
res = {CLOBBER};
y (&res);
return res;
}
__attribute__((fn spec (". ")))
real(kind=4) x ()
{
real(kind=4) __result_x;
x = {CLOBBER};
y (&__result_x);
return __result_x;
}
__attribute__((fn spec (". w ")))
void y (real(kind=4) & restrict z)
{
*z = 1.0e+0;
}
For function X (without the result clause) we should have:
__result_x = {CLOBBER};
instead. We probably need to have a closer look here:
(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 }
More information about the Gcc-bugs
mailing list