aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Duff <duff@adacore.com>2021-05-19 14:24:13 -0400
committerPierre-Marie de Rodat <derodat@adacore.com>2021-07-07 16:23:18 +0000
commit29d3965161a8c9337a8b46019eea184ff3a6ac61 (patch)
treeff38fc921294b5758f81332aade9fe3bdb0cb689
parente1eb4441733ca9b80faf4f51a29418d720014ae1 (diff)
downloadgcc-29d3965161a8c9337a8b46019eea184ff3a6ac61.zip
gcc-29d3965161a8c9337a8b46019eea184ff3a6ac61.tar.gz
gcc-29d3965161a8c9337a8b46019eea184ff3a6ac61.tar.bz2
[Ada] Optimize away certain elaboration checks
gcc/ada/ * checks.adb (Install_Primitive_Elaboration_Check): Do not generate elaboration checks for primitives if pragma Pure or Preelaborate is present. Misc comment fixes, including referring to the correct kind of check (elaboration, not accessibility). * checks.ads, restrict.adb, sem_cat.ads, sinfo.ads: Minor reformatting and comment fixes.
-rw-r--r--gcc/ada/checks.adb23
-rw-r--r--gcc/ada/checks.ads2
-rw-r--r--gcc/ada/restrict.adb5
-rw-r--r--gcc/ada/sem_cat.ads2
-rw-r--r--gcc/ada/sinfo.ads2
5 files changed, 20 insertions, 14 deletions
diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb
index 61ce9c2..cebeac5 100644
--- a/gcc/ada/checks.adb
+++ b/gcc/ada/checks.adb
@@ -48,6 +48,7 @@ with Sem; use Sem;
with Sem_Aux; use Sem_Aux;
with Sem_Ch3; use Sem_Ch3;
with Sem_Ch8; use Sem_Ch8;
+with Sem_Cat; use Sem_Cat;
with Sem_Disp; use Sem_Disp;
with Sem_Eval; use Sem_Eval;
with Sem_Mech; use Sem_Mech;
@@ -84,7 +85,7 @@ package body Checks is
-- such as Apply_Scalar_Range_Check that do not insert any code can be
-- safely called even when the Expander is inactive (but Errors_Detected
-- is 0). The benefit of executing this code when expansion is off, is
- -- the ability to emit constraint error warning for static expressions
+ -- the ability to emit constraint error warnings for static expressions
-- even when we are not generating code.
-- The above is modified in gnatprove mode to ensure that proper check
@@ -8634,7 +8635,7 @@ package body Checks is
return;
-- Do not generate an elaboration check if the related subprogram is
- -- not subjected to accessibility checks.
+ -- not subject to elaboration checks.
elsif Elaboration_Checks_Suppressed (Subp_Id) then
return;
@@ -8644,14 +8645,20 @@ package body Checks is
elsif Restriction_Active (No_Elaboration_Code) then
return;
+ -- If pragma Pure or Preelaborate applies, then these elaboration checks
+ -- cannot fail, so do not generate them.
+
+ elsif In_Preelaborated_Unit then
+ return;
+
-- Do not generate an elaboration check if exceptions cannot be used,
-- caught, or propagated.
elsif not Exceptions_OK then
return;
- -- Do not consider subprograms which act as compilation units, because
- -- they cannot be the target of a dispatching call.
+ -- Do not consider subprograms that are compilation units, because they
+ -- cannot be the target of a dispatching call.
elsif Nkind (Context) = N_Compilation_Unit then
return;
@@ -8681,10 +8688,10 @@ package body Checks is
elsif Analyzed (Subp_Body) then
return;
- -- Do not consider primitives which occur within an instance that acts
- -- as a compilation unit. Such an instance defines its spec and body out
- -- of order (body is first) within the tree, which causes the reference
- -- to the elaboration flag to appear as an undefined symbol.
+ -- Do not consider primitives that occur within an instance that is a
+ -- compilation unit. Such an instance defines its spec and body out of
+ -- order (body is first) within the tree, which causes the reference to
+ -- the elaboration flag to appear as an undefined symbol.
elsif Within_Compilation_Unit_Instance (Subp_Id) then
return;
diff --git a/gcc/ada/checks.ads b/gcc/ada/checks.ads
index 130f871..a3835d9 100644
--- a/gcc/ada/checks.ads
+++ b/gcc/ada/checks.ads
@@ -357,7 +357,7 @@ package Checks is
-- if so inserts the appropriate run-time check.
procedure Install_Primitive_Elaboration_Check (Subp_Body : Node_Id);
- -- Insert a check which ensures that subprogram body Subp_Body has been
+ -- Insert a check to ensure that subprogram body Subp_Body has been
-- properly elaborated. The check is installed only when Subp_Body is the
-- body of a nonabstract library-level primitive of a tagged type. Further
-- restrictions may apply, see the body for details.
diff --git a/gcc/ada/restrict.adb b/gcc/ada/restrict.adb
index 4f1dea4..d97a42e 100644
--- a/gcc/ada/restrict.adb
+++ b/gcc/ada/restrict.adb
@@ -396,10 +396,9 @@ package body Restrict is
N : Node_Id;
V : Uint := Uint_Minus_1)
is
- Msg_Issued : Boolean;
- pragma Unreferenced (Msg_Issued);
+ Ignore_Msg_Issued : Boolean;
begin
- Check_Restriction (Msg_Issued, R, N, V);
+ Check_Restriction (Ignore_Msg_Issued, R, N, V);
end Check_Restriction;
procedure Check_Restriction
diff --git a/gcc/ada/sem_cat.ads b/gcc/ada/sem_cat.ads
index 3fa3339..90a713b 100644
--- a/gcc/ada/sem_cat.ads
+++ b/gcc/ada/sem_cat.ads
@@ -27,7 +27,7 @@
-- the semantic restrictions required for the categorization pragmas:
--
-- Preelaborate
--- Pure,
+-- Pure
-- Remote_Call_Interface
-- Remote_Types
-- Shared_Passive
diff --git a/gcc/ada/sinfo.ads b/gcc/ada/sinfo.ads
index 25a61ad..71da7fc 100644
--- a/gcc/ada/sinfo.ads
+++ b/gcc/ada/sinfo.ads
@@ -2082,7 +2082,7 @@ package Sinfo is
-- that no elaboration check is needed on the call, because it appears in
-- the context of a local Suppress pragma. This is used on calls within
-- task bodies, where the actual elaboration checks are applied after
- -- analysis, when the local scope stack is not present
+ -- analysis, when the local scope stack is not present.
-- No_Entities_Ref_In_Spec
-- Present in N_With_Clause nodes. Set if the with clause is on the