gcc from current CVS, and also at the pre-ssa tag, both generate wrong code for the following example (a version of the Rosen trick). The basic problem seems to be that A_Type is returned by copy even though it is a return-by-reference type (it has a component, R, which is a return-by-reference type; R is a return-by-reference type because the full view is limited private). GNAT 3.15p produces the following correct result: ./x Mechanism: 2 0 1 1 2 Recent versions of gcc produce the following wrong result: ./x Mechanism: 1 0 0 1 1 ---chop here--- package B is type A_Type is limited private; function Get_The_A return A_Type; procedure Increment (An_A : A_Type); procedure Print (An_A : A_Type); private type R_Type (An_A : access A_Type) is limited null record; type A_Type is record R : R_Type (A_Type'Access); I : Integer := 0; end record; end; with Ada.Text_IO; use Ada.Text_IO; package body B is The_A : A_Type; function Get_The_A return A_Type is begin return The_A; end; procedure Increment (An_A : A_Type) is begin An_A.R.An_A.I := An_A.R.An_A.I + 1; end; procedure Print (An_A : A_Type) is begin Put_Line (An_A.I'Img); end; end; with Ada.Text_IO; use Ada.Text_IO; with B; use B; procedure X is procedure Look is The_A_Reference : A_Type renames Get_The_A; begin Print (The_A_Reference); Increment (The_A_Reference); Print (The_A_Reference); end; begin Put_Line ("Mechanism:" & Integer'Image (Get_The_A'Mechanism_Code)); New_Line; Look; New_Line; Look; end;
-- Summary: Return-by-reference type wrongly considered return-by- copy (regression) Product: gcc Version: tree-ssa Status: UNCONFIRMED Severity: normal Priority: P2 Component: ada AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: baldrick at free dot fr CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19220