aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/contracts.adb
diff options
context:
space:
mode:
authorJavier Miranda <miranda@adacore.com>2022-02-15 19:09:48 +0000
committerPierre-Marie de Rodat <derodat@adacore.com>2022-05-13 08:04:45 +0000
commitd663778287d3bd908b5e059f640ca6a02bb0f487 (patch)
treec909dc3df56af51314f1e1e4d90120413fb35afe /gcc/ada/contracts.adb
parent78e26388edb20bc827a8c0504010621f01204af2 (diff)
downloadgcc-d663778287d3bd908b5e059f640ca6a02bb0f487.zip
gcc-d663778287d3bd908b5e059f640ca6a02bb0f487.tar.gz
gcc-d663778287d3bd908b5e059f640ca6a02bb0f487.tar.bz2
[Ada] Compiler crash on -gnata -O2
gcc/ada/ * contracts.adb (Build_Unique_Name): New subprogram. (Make_Class_Precondition_Subps): Use Build_Unique_Name to generate the names of the call helpers and the name of indirect call wrappers. * freeze.adb (Needs_Wrapper): Remove dead code. (Check_Inherited_Conditions): Defer building helpers and ICW until all the dispatch table wrappers have been built and analyzed. Required to ensure uniqueness in their names because when building these wrappers for overlapped subprograms their homonym number is not definite until they have been analyzed.
Diffstat (limited to 'gcc/ada/contracts.adb')
-rw-r--r--gcc/ada/contracts.adb39
1 files changed, 30 insertions, 9 deletions
diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb
index 3cda36a..7ce3cfa 100644
--- a/gcc/ada/contracts.adb
+++ b/gcc/ada/contracts.adb
@@ -3630,6 +3630,10 @@ package body Contracts is
-- and append it to the freezing actions of Tagged_Type. Is_Dynamic
-- controls building the static or dynamic version of the helper.
+ function Build_Unique_Name (Suffix : String) return Name_Id;
+ -- Build an unique new name adding suffix to Subp_Id name (plus its
+ -- homonym number for values bigger than 1).
+
-------------------------------
-- Add_Indirect_Call_Wrapper --
-------------------------------
@@ -3710,9 +3714,7 @@ package body Contracts is
function Build_ICW_Decl return Node_Id is
ICW_Id : constant Entity_Id :=
Make_Defining_Identifier (Loc,
- New_External_Name (Chars (Subp_Id),
- Suffix => "ICW",
- Suffix_Index => Source_Offset (Loc)));
+ Build_Unique_Name (Suffix => "ICW"));
Decl : Node_Id;
Spec : Node_Id;
@@ -4049,6 +4051,29 @@ package body Contracts is
end if;
end Add_Call_Helper;
+ -----------------------
+ -- Build_Unique_Name --
+ -----------------------
+
+ function Build_Unique_Name (Suffix : String) return Name_Id is
+ begin
+ -- Append the homonym number. Strip the leading space character in
+ -- the image of natural numbers. Also do not add the homonym value
+ -- of 1.
+
+ if Has_Homonym (Subp_Id) and then Homonym_Number (Subp_Id) > 1 then
+ declare
+ S : constant String := Homonym_Number (Subp_Id)'Img;
+
+ begin
+ return New_External_Name (Chars (Subp_Id),
+ Suffix => Suffix & "_" & S (2 .. S'Last));
+ end;
+ end if;
+
+ return New_External_Name (Chars (Subp_Id), Suffix);
+ end Build_Unique_Name;
+
-- Local variables
Helper_Id : Entity_Id;
@@ -4070,9 +4095,7 @@ package body Contracts is
Helper_Id :=
Make_Defining_Identifier (Loc,
- New_External_Name (Chars (Subp_Id),
- Suffix => "DP",
- Suffix_Index => Source_Offset (Loc)));
+ Build_Unique_Name (Suffix => "DP"));
Add_Call_Helper (Helper_Id, Is_Dynamic => True);
-- Link original subprogram to helper and vice versa
@@ -4089,9 +4112,7 @@ package body Contracts is
Helper_Id :=
Make_Defining_Identifier (Loc,
- New_External_Name (Chars (Subp_Id),
- Suffix => "SP",
- Suffix_Index => Source_Offset (Loc)));
+ Build_Unique_Name (Suffix => "SP"));
Add_Call_Helper (Helper_Id, Is_Dynamic => False);