]> git.ipfire.org Git - thirdparty/gcc.git/commit
ada: Remove dependence on secondary stack for type with controlled component
authorGary Dismukes <dismukes@adacore.com>
Mon, 25 Aug 2025 23:44:41 +0000 (23:44 +0000)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 15 Sep 2025 12:59:34 +0000 (14:59 +0200)
commit91b51fc42b167eedaaded6360c490a4306bc5c55
tree3b114809a38ebc5071fa92a509a86139e30ebf95
parent10cddb6ca47def63d7ab86678082ff09416f2812
ada: Remove dependence on secondary stack for type with controlled component

There are cases where GNAT introduces a dependence on the secondary stack
in a build-in-place function with a result subtype that is definite, when
this dependence could be avoided.  In particular this is done for record
types that requires finalization due to having a controlled component.

At one time such functions required the secondary stack in order to
properly handle cases where the function might raise an exception
(to avoid improper finalization in the caller), but that is no longer
necessary.  We remove the dependence of these functions on the SS,
along with the BIPalloc formal and the generation of the big if_statement
that uses that formal.

An additional small change is to revise the condition for determining when
to generate SS mark/release within functions.

gcc/ada/ChangeLog:

* exp_ch6.ads (Make_Build_In_Place_Call_In_Allocator): Simplify comment.
* exp_ch6.adb (Make_Build_In_Place_Call_In_Allocator): Remove obsolete
comment about not being able to allocate fixed-size controlled results
on the caller side, and replace another obsolete comment with a simpler
comment. Call Build_Allocate_Deallocate_Proc when the function doesn't
need a BIPalloc formal to ensure that function results with controlled
parts allocated on the caller side will be chained for finalization.
(Make_Build_In_Place_Call_In_Object_Declaration): Call Needs_BIP_Collection
on the function's Entity_Id rather than the function call.
(Needs_BIP_Collection): If a BIP function doesn't need a BIPalloc formal
then it doesn't need a BIP collection either; return False in that case.
(Needs_BIP_Alloc_Form): Remove test of Needs_BIP_Collection.
* exp_ch7.adb (Expand_Cleanup_Actions): Move test of Uses_Sec_Stack
to be the first conjunct in setting of Needs_Sec_Stack_Mark, and put
the other tests in a disjunction subsidiary to that. Improve preceding
comment.
gcc/ada/exp_ch6.adb
gcc/ada/exp_ch6.ads
gcc/ada/exp_ch7.adb