* [COMMITTED] ada: Fix wrong finalization for qualified aggregate of limited type in allocator
@ 2023-11-30 10:19 Marc Poulhiès
0 siblings, 0 replies; only message in thread
From: Marc Poulhiès @ 2023-11-30 10:19 UTC (permalink / raw)
To: gcc-patches; +Cc: Eric Botcazou
From: Eric Botcazou <ebotcazou@adacore.com>
This happens with -gnata when the limited type has controlled components
and a predicate, because the predicate check generated for the aggregate
causes the creation of a temporary that is used as the expression of the
allocator. Now this combination is illegal for a limited type, so the
compiler does not generate the deep adjustment that would be necessary
for the access value, which ultimately results in a wrong finalization.
gcc/ada/
* checks.adb (Apply_Predicate_Check): Also deal specifically with
an expression that is a qualified aggregate in an allocator.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/checks.adb | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
index 6525982aef9..84a21b2c177 100644
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -2851,6 +2851,27 @@ package body Checks is
(Typ, Duplicate_Subexpr (Name (Par))));
return;
+ -- Similarly, if the expression is a qualified aggregate in an
+ -- allocator, apply the check to the dereference of the access
+ -- value, rather than create a temporary. This is necessary for
+ -- inherently limited types, for which the temporary is illegal.
+
+ elsif Nkind (Par) = N_Allocator then
+ declare
+ Deref : constant Node_Id :=
+ Make_Explicit_Dereference (Sloc (N),
+ Prefix => Duplicate_Subexpr (Par));
+
+ begin
+ -- This is required by Predicate_Check_In_Scope ???
+
+ Preserve_Comes_From_Source (Deref, N);
+
+ Insert_Action_After (Parent (Par),
+ Make_Predicate_Check (Typ, Deref));
+ return;
+ end;
+
-- Similarly, if the expression is an aggregate in an object
-- declaration, apply it to the object after the declaration.
--
2.42.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-11-30 10:19 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-30 10:19 [COMMITTED] ada: Fix wrong finalization for qualified aggregate of limited type in allocator Marc Poulhiès
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).