diff mbox

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

Message ID 20100618100823.GA7247@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet June 18, 2010, 10:08 a.m. UTC
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.
diff mbox

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;