aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHristian Kirtchev <kirtchev@adacore.com>2018-01-11 08:52:16 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2018-01-11 08:52:16 +0000
commit7460ccc71d2058f493068e2d02ff8af082887d6a (patch)
tree601cd7b008fd71c9bbe8dabae300ce34b9be515b
parenta5b2e4408ca5b9471e7d901b1baacf0fa9003496 (diff)
downloadgcc-7460ccc71d2058f493068e2d02ff8af082887d6a.zip
gcc-7460ccc71d2058f493068e2d02ff8af082887d6a.tar.gz
gcc-7460ccc71d2058f493068e2d02ff8af082887d6a.tar.bz2
[Ada] Secondary stack leak due to controlled component
This pach modifies the expansion related to initialization calls and secondary stack usage to inspec the components of a type derived from Limited_Controlled or Controlled. Previously controlled types were treated as never utilizing the secondary stack, however this is not true because a controlled type may contain a component initialized by a function which returns on the secondary stack. ------------ -- Source -- ------------ -- pack1.ads with Ada.Finalization; use Ada.Finalization; package Pack1 is type Ctrl is new Controlled with record Comp : Integer; end record; function Make_Ctrl return Ctrl; end Pack1; -- pack1.adb package body Pack1 is Empty : constant Ctrl := (Controlled with Comp => 123); function Make_Ctrl return Ctrl is begin return Empty; end Make_Ctrl; end Pack1; -- pack2.ads with Ada.Finalization; use Ada.Finalization; with Pack1; use Pack1; package Pack2 is type Ctrl_Wrap is new Controlled with record Comp : Ctrl := Make_Ctrl; end record; end Pack2; -- main.adb with Pack2; use Pack2; procedure Main is procedure Make_Ctrl_Wrap is Obj : Ctrl_Wrap; pragma Warnings (Off, Obj); begin null; end Make_Ctrl_Wrap; begin for Iter in 1 .. 10_000 loop Make_Ctrl_Wrap; end loop; end Main; ---------------------------- -- Compilation and output -- ---------------------------- $ gnatmake -q main.adb $ valgrind ./main >& valgrind.log $ grep -c "still reachable" valgrind.log 0 2018-01-11 Hristian Kirtchev <kirtchev@adacore.com> gcc/ada/ * sem_res.adb (Uses_SS): A controlled type requires the secondary stack if it contains at least one component declaration employing a function call returning on the secondary stack. From-SVN: r256499
-rw-r--r--gcc/ada/ChangeLog6
-rw-r--r--gcc/ada/sem_res.adb5
2 files changed, 7 insertions, 4 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index fc75731..9915a7a 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,9 @@
+2018-01-11 Hristian Kirtchev <kirtchev@adacore.com>
+
+ * sem_res.adb (Uses_SS): A controlled type requires the secondary stack
+ if it contains at least one component declaration employing a function
+ call returning on the secondary stack.
+
2018-01-11 Yannick Moy <moy@adacore.com>
* doc/gnat_rm/standard_and_implementation_defined_restrictions.rst:
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index f3bd3be..c4ed06f 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -889,10 +889,7 @@ package body Sem_Res is
Full_Type := T;
end if;
- if Is_Controlled (Full_Type) then
- return False;
-
- elsif Is_Array_Type (Full_Type) then
+ if Is_Array_Type (Full_Type) then
return Uses_SS (Component_Type (Full_Type));
elsif Is_Record_Type (Full_Type) then