* [Ada] Avoid premature finalization of a function result
@ 2020-10-16 7:35 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2020-10-16 7:35 UTC (permalink / raw)
To: gcc-patches; +Cc: Steve Baird
[-- Attachment #1: Type: text/plain, Size: 378 bytes --]
When a (simple) return statement in a function that returns a class-wide
result type returns a call to a function that returns a specific
result type, do not finalize that function result before returning it.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* exp_util.adb (Is_Related_To_Func_Return): Cope with the case
where the FE introduces a type conversion.
[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 871 bytes --]
diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -8740,9 +8740,14 @@ package body Exp_Util is
function Is_Related_To_Func_Return (Id : Entity_Id) return Boolean is
Expr : constant Node_Id := Related_Expression (Id);
begin
+ -- In the case of a function with a class-wide result that returns
+ -- a call to a function with a specific result, we introduce a
+ -- type conversion for the return expression. We do not want that
+ -- type conversion to influence the result of this function.
+
return
Present (Expr)
- and then Nkind (Expr) = N_Explicit_Dereference
+ and then Nkind (Unqual_Conv (Expr)) = N_Explicit_Dereference
and then Nkind (Parent (Expr)) = N_Simple_Return_Statement;
end Is_Related_To_Func_Return;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-10-16 7:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-16 7:35 [Ada] Avoid premature finalization of a function result Pierre-Marie de Rodat
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).