]> git.ipfire.org Git - thirdparty/gcc.git/commit
ada: Fix crash on expression function returning tagged type in nested package
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 4 Jul 2024 21:35:01 +0000 (23:35 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 2 Aug 2024 07:08:03 +0000 (09:08 +0200)
commit058e5fd2bd1f18e2c1b6bd1fc02e77560d99f8e8
tree874a6de386c4d1640920e20a71762e38470392ba
parent99337cb2385c38182e48a491442da449c028f51c
ada: Fix crash on expression function returning tagged type in nested package

This happens when the expression is a reference to a formal parameter of
the function, or a conditional expression with such a reference as one of
its dependent expressions, because the RM 6.5(8/5) subclause prescribes a
tag reassignment in this case, which requires freezing the tagged type in
the GNAT freezing model, although the language says there is no freezing.

In other words, it's another occurrence of the discrepancy between this
model tailored to Ada 95 and the freezing rules introduced in Ada 2012,
that is papered over by Should_Freeze_Type and the associated processing.

gcc/ada/

* exp_util.ads (Is_Conversion_Or_Reference_To_Formal): New
function declaration.
* exp_util.adb (Is_Conversion_Or_Reference_To_Formal): New
function body.
* exp_ch6.adb (Expand_Simple_Function_Return): Call the predicate
Is_Conversion_Or_Reference_To_Formal in order to decide whether a
tag check or reassignment is needed.
* freeze.adb (Should_Freeze_Type): Move declaration and body to
the appropriate places. Also return True for tagged results
subject to the expansion done in Expand_Simple_Function_Return
that is guarded by the predicate
Is_Conversion_Or_Reference_To_Formal.
gcc/ada/exp_ch6.adb
gcc/ada/exp_util.adb
gcc/ada/exp_util.ads
gcc/ada/freeze.adb