]> git.ipfire.org Git - thirdparty/gcc.git/commit
Preserve TREE_THIS_NOTRAP during inlining in more cases
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 17 Sep 2025 09:31:17 +0000 (11:31 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Wed, 17 Sep 2025 09:38:26 +0000 (11:38 +0200)
commitd81e24bbb930e238305c42f1c1251947e1b35b6a
treede83dad08f65ed03cd7c2f4c14bfa9bd5564b82d
parent8a7346964d984667d452fa46ea5ace5b372fb8fb
Preserve TREE_THIS_NOTRAP during inlining in more cases

For parameters passed by reference, the Ada compiler sets TREE_THIS_NOTRAP
on their dereference to prevent tree_could_trap_p from returning true and
then causing a new basic block to be created for every access to them,
given that in Ada the -fnon-call-exceptions flag is enabled by default.

However, when the subprogram is inlined, this TREE_THIS_NOTRAP flag cannot
be blindly preserved because the call may pass the dereference of a pointer
as the argument: even if the compiler generates a check that the pointer is
not null just before, preserving TREE_THIS_NOTRAP could cause an access to
be hoisted before the check; therefore it gets cleared for parameters.

Now that's suboptimal if the argument is a full object because accessing it
through the dereference of the parameter cannot trap, which causes MEM_REFs
of the form MEM_REF [&DECL] to be considered as trapping in the case where
the nominal subtype of DECL is self-referential.

gcc/
* tree-inline.cc (maybe_copy_this_notrap): New function.  Also copy
the TREE_THIS_NOTRAP flag for parameters when the argument is a full
object and the parameter's type is self-referential.
(remap_gimple_op_r): Call maybe_copy_this_notrap.
(copy_tree_body_r): Likewise.
gcc/tree-inline.cc