Commit abc856cf by Hristian Kirtchev Committed by Pierre-Marie de Rodat

[Ada] Spurious visibility error in inlined function

This patch corrects the use of tree replication when inlining a function
that returns an unconstrained result, and its sole statement is an
extended return statement. The use of New_Copy_Tree ensires that global
references saved in a generic template are properly carried over when
the function is instantiated and inlined.

2019-07-03  Hristian Kirtchev  <kirtchev@adacore.com>

gcc/ada/

	* inline.adb (Build_Return_Object_Formal): New routine.
	(Can_Split_Unconstrained_Function): Code clean up.
	(Copy_Formals,Copy_Return_Object): New routines.
	(Split_Unconstrained_Function): Code clean up and refactoring.

gcc/testsuite/

	* gnat.dg/inline15.adb, gnat.dg/inline15_gen.adb,
	gnat.dg/inline15_gen.ads, gnat.dg/inline15_types.ads: New
	testcase.

From-SVN: r272980
parent 866000e7
2019-07-03 Hristian Kirtchev <kirtchev@adacore.com>
* inline.adb (Build_Return_Object_Formal): New routine.
(Can_Split_Unconstrained_Function): Code clean up.
(Copy_Formals,Copy_Return_Object): New routines.
(Split_Unconstrained_Function): Code clean up and refactoring.
2019-07-03 Gary Dismukes <dismukes@adacore.com>
* bindo-augmentors.adb, bindo-augmentors.ads,
......
2019-07-03 Hristian Kirtchev <kirtchev@adacore.com>
* gnat.dg/inline15.adb, gnat.dg/inline15_gen.adb,
gnat.dg/inline15_gen.ads, gnat.dg/inline15_types.ads: New
testcase.
2019-07-03 Bob Duff <duff@adacore.com>
* gnat.dg/warn20.adb, gnat.dg/warn20_pkg.adb,
......
-- { dg-do compile }
-- { dg-options "-O2" }
with Inline15_Gen;
procedure Inline15 is
package Inst is new Inline15_Gen;
begin
Inst.Call_Func;
end Inline15;
package body Inline15_Gen is
function Initialize (Val : Inline15_Types.Enum) return Inline15_Types.Rec;
procedure Print (Val : Inline15_Types.Rec);
procedure Call_Func is
Result : constant Inline15_Types.Rec := Func (Inline15_Types.Two);
begin
null;
end Call_Func;
function Func (Val : Inline15_Types.Enum) return Inline15_Types.Rec is
begin
return Result : constant Inline15_Types.Rec := Initialize (Val) do
Print (Result);
end return;
end Func;
function Initialize (Val : Inline15_Types.Enum) return Inline15_Types.Rec is
pragma Warnings (Off);
Result : Inline15_Types.Rec (Val);
pragma Warnings (On);
begin
return Result;
end Initialize;
procedure Print (Val : Inline15_Types.Rec) is begin null; end Print;
end Inline15_Gen;
-- gen.ads
with Inline15_Types;
generic
package Inline15_Gen is
function Func (Val : Inline15_Types.Enum) return Inline15_Types.Rec with Inline;
procedure Call_Func with Inline;
end Inline15_Gen;
package Inline15_Types is
type Enum is (One, Two, Three, Four);
type Rec (Discr : Enum) is record
Comp_1 : Integer;
case Discr is
when One =>
Comp_2 : Float;
when Two =>
Comp_3 : Boolean;
Comp_4 : Long_Float;
when others =>
null;
end case;
end record;
end Inline15_Types;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment