This patch corrects the machinery which detects whether a particular transient
context may raise an exception. Examine the original expression of an object
declaration node because a function call that returns on the secondary stack
may have been rewritten into something else and no longer appear as a call.

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

2012-07-23  Hristian Kirtchev  <kirtc...@adacore.com>

        * exp_ch7.adb (Requires_Hooking): Examine the original expression
        of an object declaration node because a function call that
        returns on the secondary stack may have been rewritten into
        something else.

Index: exp_ch7.adb
===================================================================
--- exp_ch7.adb (revision 189768)
+++ exp_ch7.adb (working copy)
@@ -4369,12 +4369,16 @@
          function Requires_Hooking return Boolean is
          begin
             --  The context is either a procedure or function call or an object
-            --  declaration initialized by a function call. In all these cases,
-            --  the calls might raise an exception.
+            --  declaration initialized by a function call. Note that in the
+            --  latter case, a function call that returns on the secondary
+            --  stack is usually rewritten into something else. Its proper
+            --  detection requires examination of the original initialization
+            --  expression.
 
             return Nkind (N) in N_Subprogram_Call
-               or else (Nkind (N) = N_Object_Declaration
-                         and then Nkind (Expression (N)) = N_Function_Call);
+              or else (Nkind (N) = N_Object_Declaration
+                         and then Nkind (Original_Node (Expression (N))) =
+                                    N_Function_Call);
          end Requires_Hooking;
 
          --  Local variables

Reply via email to