Patchwork [Ada] Fix error in short circuit expansion with -gnatd.X

login
register
mail settings
Submitter Arnaud Charlet
Date June 18, 2010, 10:08 a.m.
Message ID <20100618100823.GA7247@adacore.com>
Download mbox | patch
Permalink /patch/56159/
State New
Headers show

Comments

Arnaud Charlet - June 18, 2010, 10:08 a.m.
This patch fixes an error in the code of leaving the Actions field
set after copying its contents to an N_Expression_With_Actions node.
In the conditional expression case, this probably has no functional
effect (but is cleaner), but in the short circuit case, the failure
to clear the actions field was causing strange double expansion.
The following test, compiled with -gnatd.X showed this error and
resulted in a failure in the back end. It now compiles cleanly.

package DoubleActions is
   package Names is
      type Text (Max_Length : Natural) is record
         Value : String (1..Max_Length);
      end record;
      type Name_Type is record
         Value : Text (30);
      end record;
   end Names;
   type Link_Type is record
      Table_1_Name : Names.Name_Type;
      Table_2_Name : Names.Name_Type;
   end record;
   procedure Put (Link : Link_Type);
end DoubleActions;

package body DoubleActions is
   procedure Put (Link : Link_Type) is
   begin
      if Names."=" (Link.Table_1_Name, Link.Table_2_Name) then
         raise Program_Error;
       end if;
   end;
end Double_Actions;

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

2010-06-18  Robert Dewar  <dewar@adacore.com>

	* exp_ch4.adb (Expand_N_Conditional_Expression): Clear Actions field
	when we create N_Expression_With_Actions node.
	(Expand_Short_Circuit): Ditto.

Patch

Index: exp_ch4.adb
===================================================================
--- exp_ch4.adb	(revision 160971)
+++ exp_ch4.adb	(working copy)
@@ -4111,6 +4111,7 @@  package body Exp_Ch4 is
                  Make_Expression_With_Actions (Sloc (Thenx),
                    Actions    => Then_Actions (N),
                    Expression => Relocate_Node (Thenx)));
+               Set_Then_Actions (N, No_List);
                Analyze_And_Resolve (Thenx, Typ);
             end if;
 
@@ -4119,6 +4120,7 @@  package body Exp_Ch4 is
                  Make_Expression_With_Actions (Sloc (Elsex),
                    Actions    => Else_Actions (N),
                    Expression => Relocate_Node (Elsex)));
+               Set_Else_Actions (N, No_List);
                Analyze_And_Resolve (Elsex, Typ);
             end if;
 
@@ -9044,6 +9046,7 @@  package body Exp_Ch4 is
               Make_Expression_With_Actions (LocR,
                 Expression => Relocate_Node (Right),
                 Actions    => Actlist));
+            Set_Actions (N, No_List);
             Analyze_And_Resolve (Right, Standard_Boolean);
          end if;