[Ada] Fix bug in object.method notation

Arnaud Charlet charlet@adacore.com
Mon Jul 4 13:52:00 GMT 2005

Tested on i686-linux, committed on mainline.

When analyzing a call of the form object.method (...), the call is rewritten
into its canonical method (object, ...), and then resolution is attempted
on this candidate rewritten form.
Get_First_Interp is called on a copy of each actual that was created
when constructing the candidate form, but when the actual is an overloaded
function call, the interpretations which were stored for the original
actual are not available, which causes the compiler to crash.
This is fixed by carrying the collected interpretations from the original
actual to the copy used in the candidate rewritten call.
Test case:
$ gcc -c -gnatQ -gnatf -gnat05 -gnatwa -I- -gnatA compilation_results.adb
must not cause a compiler crash.
--  Source code follows
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Containers.Indefinite_Vectors;
procedure Compilation_Results is
   package Vectors is new Ada.Containers.Indefinite_Vectors
     (Index_Type   => Natural,
      Element_Type => Ada.Strings.Unbounded.Unbounded_String,
      "="          => Ada.Strings.Unbounded."=");
   use Vectors;
   S  : Vectors.Vector;
   S.Append (To_Unbounded_String (""));
end Compilation_Results;

2005-07-04  Thomas Quinot  <quinot@adacore.com>

	* sem_ch4.adb (Transform_Object_Operation): For an actual that is an
	overloaded function call, carry interpretations from the original tree
	to the copy.

-------------- next part --------------
Index: sem_ch4.adb
RCS file: /cvs/gcc/gcc/gcc/ada/sem_ch4.adb,v
retrieving revision 1.41
diff -u -p -r1.41 sem_ch4.adb
--- sem_ch4.adb	1 Jul 2005 01:28:00 -0000	1.41
+++ sem_ch4.adb	4 Jul 2005 13:19:31 -0000
@@ -4913,7 +4913,19 @@ package body Sem_Ch4 is
                Actual := First (Parameter_Associations (Parent_Node));
                while Present (Actual) loop
-                  Append (New_Copy_Tree (Actual), Actuals);
+                  declare
+                     New_Actual : constant Node_Id := New_Copy_Tree (Actual);
+                  begin
+                     Append (New_Actual, Actuals);
+                     if Nkind (Actual) = N_Function_Call
+                       and then Is_Overloaded (Name (Actual))
+                     then
+                        Save_Interps (Name (Actual), Name (New_Actual));
+                     end if;
+                  end;
                   Next (Actual);
                end loop;

More information about the Gcc-patches mailing list