aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/contracts.adb
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2018-09-26 09:16:28 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2018-09-26 09:16:28 +0000
commit33d2551767100d004ffa85efbd1165cb731dc87d (patch)
tree2e9a021faa638f307b95c2e1fbeea3e4ba315c44 /gcc/ada/contracts.adb
parentf0f2d1fc033cbe56098f7261d91ef6a8130d0b27 (diff)
downloadgcc-33d2551767100d004ffa85efbd1165cb731dc87d.zip
gcc-33d2551767100d004ffa85efbd1165cb731dc87d.tar.gz
gcc-33d2551767100d004ffa85efbd1165cb731dc87d.tar.bz2
[Ada] Fix ICE related to type freezing
2018-09-26 Ed Schonberg <schonberg@adacore.com> gcc/ada/ * contracts.adb (Expand_Subprogram_Contract, Process_Preconditions_For): Apply Freeze_Expr_Types to the expression for a precondition of an expression function that is a completion, when the completion appears in the private part and the declaration it completes is in the visible part of the same package. * freeze.adb (Freeze_Expr_Types): Do not establish the scope of the operation if it is already installed, as will be the case when called to analyze the contract oc the subprogram (which happens when generating code inside the subprogram body). From-SVN: r264602
Diffstat (limited to 'gcc/ada/contracts.adb')
-rw-r--r--gcc/ada/contracts.adb26
1 files changed, 24 insertions, 2 deletions
diff --git a/gcc/ada/contracts.adb b/gcc/ada/contracts.adb
index 26a8d28..136c05c 100644
--- a/gcc/ada/contracts.adb
+++ b/gcc/ada/contracts.adb
@@ -33,6 +33,7 @@ with Exp_Prag; use Exp_Prag;
with Exp_Tss; use Exp_Tss;
with Exp_Util; use Exp_Util;
with Freeze; use Freeze;
+with Lib; use Lib;
with Namet; use Namet;
with Nlists; use Nlists;
with Nmake; use Nmake;
@@ -591,7 +592,8 @@ package body Contracts is
if Skip_Assert_Exprs then
null;
- -- Otherwise analyze the pre/postconditions. Their expressions
+ -- Otherwise analyze the pre/postconditions.
+ -- If these come from an aspect specification, their expressions
-- might include references to types that are not frozen yet, in the
-- case where the body is a rewritten expression function that is a
-- completion, so freeze all types within before constructing the
@@ -2856,12 +2858,25 @@ package body Contracts is
procedure Process_Preconditions_For (Subp_Id : Entity_Id) is
Items : constant Node_Id := Contract (Subp_Id);
+ Bod : constant Node_Id := Unit_Declaration_Node (Body_Id);
Decl : Node_Id;
+ Freeze_T : Boolean;
Prag : Node_Id;
Subp_Decl : Node_Id;
begin
- -- Process the contract
+ -- Process the contract. If the body is an expression function
+ -- that is a completion, freeze types within, because this may
+ -- not have been done yet, when the subprogram declaration and
+ -- its completion by an expression function appear in distinct
+ -- declarative lists of the same unit (visible and private).
+
+ Freeze_T := Was_Expression_Function (Bod)
+ and then Sloc (Body_Id) /= Sloc (Subp_Id)
+ and then In_Same_Source_Unit (Body_Id, Subp_Id)
+ and then List_Containing (Bod) /=
+ List_Containing (Unit_Declaration_Node (Subp_Id))
+ and then not In_Instance;
if Present (Items) then
Prag := Pre_Post_Conditions (Items);
@@ -2869,6 +2884,13 @@ package body Contracts is
if Pragma_Name (Prag) = Name_Precondition
and then Is_Checked (Prag)
then
+ if Freeze_T
+ and then Present (Corresponding_Aspect (Prag))
+ then
+ Freeze_Expr_Types (Subp_Id, Standard_Boolean,
+ Expression (Corresponding_Aspect (Prag)), Bod);
+ end if;
+
Prepend_To_Decls_Or_Save (Prag);
end if;