From patchwork Wed Jun 23 10:21:51 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Ada] Secondary stack usage and operators that rename functions Date: Wed, 23 Jun 2010 00:21:51 -0000 From: Arnaud Charlet X-Patchwork-Id: 56666 Message-Id: <20100623102151.GA2065@adacore.com> To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg 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; begin null; end; Top : Mark_Id := SS_Mark; begin for I in 1 .. 5 loop P; 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 * 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. 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))