This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Fix error in handling of unchecked_deallocation


Tested on i686-linux, committed on trunk

This patch corrects two significant errors in Expand_Unc_Deallocation
that combined to cause a nasty regression. First, the code checked for
being enclosed within an IF statement checking for null. That's wrong
in the case where the variable gets reset to null within the if as in
the test below. Second, the inserted statements were in analyzed before
being wrapped in an IF, resulting in bogus updates to Current_Values,
which, given enhancements in that area, were more damaging than before.

The following test program was raising a CE (and you could see in the
expansion that the IF statement guarding the deallocation was missing).
This program now executes successfully generating the output:

Run...
...End.

with Ada.Strings.Unbounded;      use Ada.Strings.Unbounded;
with Ada.Text_IO;
with Ada.Unchecked_Deallocation;
procedure Acf is
   use Ada;
   type Nkind is (Info, Text);
   type Node;
   type Tree is access Node;
   type Node (Kind : Nkind) is record
      Next : Tree;
      Line : Natural;
      case Kind is
         when Info => Filename : Unbounded_String;
         when Text => null;
         when others => null;
      end case;
   end record;
   procedure Free is new Unchecked_Deallocation (Node, Tree);
   procedure Release (T : in out Tree; Include : in Boolean := True) is
   begin
      if T = null then return; end if;
      case T.Kind is
         when Text => T := null;
         when others => null;
      end case;
      Free (T);
   end Release;
   V : Tree := new Node'(Text, null, 1);
begin
   Text_IO.Put_Line ("Run...");
   Release (V);
   Text_IO.Put_Line ("...End.");
end Acf;

2006-02-13  Robert Dewar  <dewar@adacore.com>

	* exp_intr.adb (Expand_Unc_Deallocation): Correct error of bad analyze
	call.

Attachment: difs.48
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]