[Ada] Secondary stack usage and operators that rename functions

Submitted by Arnaud Charlet on June 23, 2010, 10:21 a.m.


Message ID 20100623102151.GA2065@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet June 23, 2010, 10:21 a.m.
To determine whether a function that returns a record type uses the secondary
stack, we examine the expressions of each component definition and return true
if any of them is a function call that itself uses the secondary stack. This
patch corrects an omission: the call may have been written as a operator in
prefix or infix notation.

The following must compile and execute quietly:

with Ada.Strings.Unbounded;use Ada.Strings.Unbounded;
pragma Warnings (Off);
with system.secondary_stack; use system.secondary_stack;
procedure SS_Leak is

   function "+" (Item : in String) return Unbounded_String
      renames To_Unbounded_String;

   type Rate_Record is record
      Feed_Id    : Unbounded_String := +"Y";
   end record;

   procedure P is
      x : Rate_Record;
   Top : Mark_Id := SS_Mark;
   for I in 1 .. 5 loop
      if SS_Mark /= Top then
         raise Constraint_Error;
      end if;
   end loop;
end SS_Leak;

Tested on x86_64-pc-linux-gnu, committed on trunk

2010-06-23  Ed Schonberg  <schonberg@adacore.com>

	* sem_res.adb (Uses_SS): The expression that initializes a controlled
	component of a record type may be a user-defined operator that is
	rewritten as a function call.

Patch hide | download patch | download mbox

Index: sem_res.adb
--- sem_res.adb	(revision 161265)
+++ sem_res.adb	(working copy)
@@ -906,10 +906,12 @@  package body Sem_Res is
                   Expr := Original_Node (Expression (Parent (Comp)));
                   --  Return True if the expression is a call to a function
-                  --  (including an attribute function such as Image) with
-                  --  a result that requires a transient scope.
+                  --  (including an attribute function such as Image, or a
+                  --  user-defined operator) with a result that requires a
+                  --  transient scope.
                   if (Nkind (Expr) = N_Function_Call
+                       or else Nkind (Expr) in N_Op
                        or else (Nkind (Expr) = N_Attribute_Reference
                                  and then Present (Expressions (Expr))))
                     and then Requires_Transient_Scope (Etype (Expr))