aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHristian Kirtchev <kirtchev@adacore.com>2018-07-31 09:56:31 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2018-07-31 09:56:31 +0000
commit51d4bdfb567c86de722ac5a72b79c8f51209228c (patch)
treeea43af4ecfb4db9028a815e3a8fd9c238e842c63
parent51f2fc7d760f66a0cd4842a2dad450a25dc70c21 (diff)
downloadgcc-51d4bdfb567c86de722ac5a72b79c8f51209228c.zip
gcc-51d4bdfb567c86de722ac5a72b79c8f51209228c.tar.gz
gcc-51d4bdfb567c86de722ac5a72b79c8f51209228c.tar.bz2
[Ada] Secondary stack leak with access-to-subprogram
This patch modifies call resolution to recognize when the designated type of an access-to-subprogram requires secondary stack management, and establish the proper transient block. ------------ -- Source -- ------------ -- leak7.adb procedure Leak7 is Max_Iterations : constant := 10_000; function Func return String is begin return "Will this leak? Or will it dry?"; end Func; type Func_Ptr is access function return String; procedure Anonymous_Leak (Func : access function return String) is begin for Iteration in 1 .. Max_Iterations loop declare Val : constant String := Func.all; begin null; end; end loop; end Anonymous_Leak; procedure Named_Leak (Func : Func_Ptr) is begin for Iteration in 1 .. Max_Iterations loop declare Val : constant String := Func.all; begin null; end; end loop; end Named_Leak; begin Anonymous_Leak (Func'Access); Named_Leak (Func'Access); end Leak7; ---------------------------- -- Compilation and output -- ---------------------------- $ gnatmake -q leak7.adb $ valgrind ./leak7 >& leak7.txt $ grep -c "still reachable" leak7.txt 0 2018-07-31 Hristian Kirtchev <kirtchev@adacore.com> gcc/ada/ * sem_res.adb (Resolve_Call): Establish a transient scope to manage the secondary stack when the designated type of an access-to-subprogram requires it. From-SVN: r263103
-rw-r--r--gcc/ada/ChangeLog6
-rw-r--r--gcc/ada/sem_res.adb2
2 files changed, 7 insertions, 1 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 8207826..43d837b 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,9 @@
+2018-07-31 Hristian Kirtchev <kirtchev@adacore.com>
+
+ * sem_res.adb (Resolve_Call): Establish a transient scope to
+ manage the secondary stack when the designated type of an
+ access-to-subprogram requires it.
+
2018-07-31 Ed Schonberg <schonberg@adacore.com>
* exp_ch7.adb (Check_Unnesting_Elaboration_Code): To find local
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index 5f9f1c3..ddfa543 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -6433,7 +6433,7 @@ package body Sem_Res is
null;
elsif Expander_Active
- and then Ekind (Nam) = E_Function
+ and then Ekind_In (Nam, E_Function, E_Subprogram_Type)
and then Requires_Transient_Scope (Etype (Nam))
then
Establish_Transient_Scope (N, Manage_Sec_Stack => True);