aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJavier Miranda <miranda@adacore.com>2023-03-26 11:45:50 +0000
committerMarc Poulhiès <poulhies@adacore.com>2023-05-26 09:29:19 +0200
commit3e62561d5ffbb07fa97a4dddfd729fceb7cfce75 (patch)
tree5680497c88b5cc1a6d0b73ebe1597e5ae628193d /gcc
parent54783e61dd9bfd0f0289890ba9240deeef1af81a (diff)
downloadgcc-3e62561d5ffbb07fa97a4dddfd729fceb7cfce75.zip
gcc-3e62561d5ffbb07fa97a4dddfd729fceb7cfce75.tar.gz
gcc-3e62561d5ffbb07fa97a4dddfd729fceb7cfce75.tar.bz2
ada: Crash on function returning allocated object containing tasks
The frontend crashes when a function returns an object of a limited type that may have task components, has discriminants, and the object is created with an allocator. gcc/ada/ * exp_ch4.adb (Expand_N_Allocator): If an allocator with constraints is called in the return statement of a function returning a general access type, then propagate to the itype the master of the general access type (since it is the master associated with the returned object).
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/exp_ch4.adb19
1 files changed, 19 insertions, 0 deletions
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index f894da5..5c9c668 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -4991,6 +4991,25 @@ package body Exp_Ch4 is
Expand_N_Full_Type_Declaration
(Parent (Base_Type (PtrT)));
+ -- When the allocator has a subtype indication then a
+ -- constraint is present and an itype has been added by
+ -- Analyze_Allocator as the subtype of this allocator.
+
+ -- If an allocator with constraints is called in the
+ -- return statement of a function returning a general
+ -- access type, then propagate to the itype the master
+ -- of the general access type (since it is the master
+ -- associated with the returned object).
+
+ elsif Is_Itype (PtrT)
+ and then Ekind (Current_Scope) = E_Function
+ and then Ekind (Etype (Current_Scope))
+ = E_General_Access_Type
+ and then In_Return_Value (N)
+ then
+ Set_Master_Id (PtrT,
+ Master_Id (Etype (Current_Scope)));
+
-- The only other possibility is an itype. For this
-- case, the master must exist in the context. This is
-- the case when the allocator initializes an access