diff mbox

[Ada] Crash on use of 'Old

Message ID 20110829094133.GA27785@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Aug. 29, 2011, 9:41 a.m. UTC
The Ada2012 attribute 'Old is expanded into an object declaration that captures
the value of a formal before execution.  This patch fixes a bug that placed the
object declaration in the wrong scope  when the enclosing subprogram body had
a single local declaration for a use clause.

The following must compile quietly:

gnatmake -q  -gnat12 -gnata p1-tests.adb

--
package P1 is
   package P2 is

      procedure Q (X : in out Integer);
      pragma Test_Case (Name => "Test case 1",
                        Mode => Robustness,
                        Ensures => X = X'Old);
   end P2;
end P1;
---
package P1.Tests is
   package P2_Tests is
      procedure Test_Q;
   end P2_Tests;
end P1.Tests;
---
with Ada.Text_IO;
separate (P1.Tests)
package body P2_Tests is
   procedure Wrap_Q_3 (X : in out Integer)
   is
      use P1.P2;
   begin
      Q (X);
      if X = X'Old then
         Ada.Text_IO.Put_Line ("postcondition violated");
      end if;
   end Wrap_Q_3;

   procedure Test_Q is
   begin
      null;
   end Test_Q;
end P2_Tests;
---
package body P1.Tests is
   package body P2_Tests is separate;
end P1.Tests;
---
package body P1 is
   package body P2 is
      procedure Q (X : in out Integer) is
      begin
         null;
      end Q;
   end P2;
end P1;
---

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

2011-08-29  Ed Schonberg  <schonberg@adacore.com>

	* exp_util.adb (Insert_Actions): Use clauses can be part of lists of
	declarations, and thus are likely insertion points for actions.
diff mbox

Patch

Index: exp_util.adb
===================================================================
--- exp_util.adb	(revision 178162)
+++ exp_util.adb	(working copy)
@@ -3028,6 +3028,11 @@ 
                N_Task_Body_Stub                         |
                N_Task_Type_Declaration                  |
 
+               --  Use clauses can appear in lists of declarations
+
+               N_Use_Package_Clause                     |
+               N_Use_Type_Clause                        |
+
                --  Freeze entity behaves like a declaration or statement
 
                N_Freeze_Entity
@@ -3328,8 +3333,6 @@ 
                N_Unconstrained_Array_Definition         |
                N_Unused_At_End                          |
                N_Unused_At_Start                        |
-               N_Use_Package_Clause                     |
-               N_Use_Type_Clause                        |
                N_Variant                                |
                N_Variant_Part                           |
                N_Validate_Unchecked_Conversion          |