public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Bob Duff <duff@adacore.com>
Subject: [COMMITTED] ada: Remove incorrect comments about initialization
Date: Mon, 14 Nov 2022 14:52:52 +0100	[thread overview]
Message-ID: <20221114135252.53221-1-poulhies@adacore.com> (raw)

From: Bob Duff <duff@adacore.com>

Cleanup only; no change in behavior.

This patch removes and rewrites some comments regarding initialization.
These initializions are needed, so there's no need to apologize for
initializing these variables.

Note that -gnatVa is not relevant; reads of uninitialized variables
are wrong, whether or not we get caught.

gcc/ada/

	* atree.ads: Remove some comments.
	* err_vars.ads: Likewise.
	* scans.ads: Likewise.
	* sinput.ads: Likewise.
	* checks.ads: Likewise. Also add a "???" comment indicating an
	obsolete comment that is too difficult to correct at this time.
	* sem_attr.adb: Minor comment rewrite.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/atree.ads    |  6 ++----
 gcc/ada/checks.ads   | 25 ++++++++++---------------
 gcc/ada/err_vars.ads |  7 -------
 gcc/ada/scans.ads    | 27 ++++++++++++---------------
 gcc/ada/sem_attr.adb |  2 +-
 gcc/ada/sinput.ads   |  2 --
 6 files changed, 25 insertions(+), 44 deletions(-)

diff --git a/gcc/ada/atree.ads b/gcc/ada/atree.ads
index 0c809f56435..cc66ab3777c 100644
--- a/gcc/ada/atree.ads
+++ b/gcc/ada/atree.ads
@@ -148,7 +148,6 @@ package Atree is
    --  This is a count of errors that are serious enough to stop expansion,
    --  and hence to prevent generation of an object file even if the
    --  switch -gnatQ is set. Initialized to zero at the start of compilation.
-   --  Initialized for -gnatVa use, see comment above.
 
    --  WARNING: There is a matching C declaration of this variable in fe.h
 
@@ -156,12 +155,11 @@ package Atree is
    --  Number of errors detected so far. Includes count of serious errors and
    --  non-serious errors, so this value is always greater than or equal to the
    --  Serious_Errors_Detected value. Initialized to zero at the start of
-   --  compilation. Initialized for -gnatVa use, see comment above.
+   --  compilation.
 
    Warnings_Detected : Nat := 0;
    --  Number of warnings detected. Initialized to zero at the start of
-   --  compilation. Initialized for -gnatVa use, see comment above. This
-   --  count includes the count of style and info messages.
+   --  compilation. This count includes the count of style and info messages.
 
    Warning_Info_Messages : Nat := 0;
    --  Number of info messages generated as warnings. Info messages are never
diff --git a/gcc/ada/checks.ads b/gcc/ada/checks.ads
index 48678cd01df..a7d05a3fa39 100644
--- a/gcc/ada/checks.ads
+++ b/gcc/ada/checks.ads
@@ -776,12 +776,14 @@ package Checks is
    --           itself lead to erroneous or unpredictable execution, or to
    --           other objects becoming abnormal.
 
-   --  We quote the rules in full here since they are quite delicate. Most
-   --  of the time, we can just compute away with wrong values, and get a
-   --  possibly wrong result, which is well within the range of allowed
-   --  implementation defined behavior. The two tricky cases are subscripted
-   --  array assignments, where we don't want to do wild stores, and case
-   --  statements where we don't want to do wild jumps.
+   --  We quote the rules in full here since they are quite delicate.
+   --  (???The rules quoted here are obsolete; see the GNAT User's Guide for a
+   --  description of all the -gnatV switches.) Most of the time, we can just
+   --  compute away with wrong values, and get a possibly wrong result, which
+   --  is well within the range of allowed implementation defined behavior. The
+   --  two tricky cases are subscripted array assignments, where we don't want
+   --  to do wild stores, and case statements where we don't want to do wild
+   --  jumps.
 
    --  In GNAT, we control validity checking with a switch -gnatV that can take
    --  three parameters, n/d/f for None/Default/Full. These modes have the
@@ -799,15 +801,8 @@ package Checks is
    --        alternatives will be executed. Wild jumps cannot result even
    --        in this mode, since we always do a range check
 
-   --        For subscripted array assignments, wild stores will result in
-   --        the expected manner when addresses are calculated using values
-   --        of subscripts that are out of range.
-
-   --      It could perhaps be argued that this mode is still conformant with
-   --      the letter of the RM, since implementation defined is a rather
-   --      broad category, but certainly it is not in the spirit of the
-   --      RM requirement, since wild stores certainly seem to be a case of
-   --      erroneous behavior.
+   --        For subscripted array assignments, wild stores can result in
+   --        overwriting arbitrary memory locations.
 
    --    Default (default standard RM-compatible validity checking)
 
diff --git a/gcc/ada/err_vars.ads b/gcc/ada/err_vars.ads
index 79d5f319f59..66c4bb09b4c 100644
--- a/gcc/ada/err_vars.ads
+++ b/gcc/ada/err_vars.ads
@@ -32,12 +32,6 @@ with Uintp; use Uintp;
 
 package Err_Vars is
 
-   --  All of these variables are set when needed, so they do not need to be
-   --  initialized. However, there is code that saves and restores existing
-   --  values, which may malfunction in -gnatVa mode if the variable has never
-   --  been initialized, so we initialize some variables to avoid exceptions
-   --  from invalid values in such cases.
-
    --  Note on error counts (Serious_Errors_Detected, Total_Errors_Detected,
    --  Warnings_Detected, Warning_Info_Messages, Report_Info_Messages). These
    --  counts might more logically appear in this unit, but we place them
@@ -68,7 +62,6 @@ package Err_Vars is
    --  resulting from illegalities, and also for substitution of more
    --  appropriate error messages from higher semantic levels. It is
    --  a counter so that the increment/decrement protocol nests neatly.
-   --  Initialized for -gnatVa use, see comment above.
 
    Error_Msg_Exception : exception;
    --  Exception raised if Raise_Exception_On_Error is true
diff --git a/gcc/ada/scans.ads b/gcc/ada/scans.ads
index dbe9e5a7242..ddb4c3efb72 100644
--- a/gcc/ada/scans.ads
+++ b/gcc/ada/scans.ads
@@ -358,38 +358,35 @@ package Scans is
    --  Note: these variables can only be referenced during the parsing of a
    --  file. Reference to any of them from Sem or the expander is wrong.
 
-   --  These variables are initialized as required by Scn.Initialize_Scanner,
-   --  and should not be referenced before such a call. However, there are
-   --  situations in which these variables are saved and restored, and this
-   --  may happen before the first Initialize_Scanner call, resulting in the
-   --  assignment of invalid values. To avoid this, and allow building with
-   --  the -gnatVa switch, we initialize some variables to known valid values.
-
-   Scan_Ptr : Source_Ptr := No_Location; -- init for -gnatVa
+   --  These variables are initialized by Scn.Initialize_Scanner, and should
+   --  not be referenced before such a call, except for saving and restoring
+   --  them.
+
+   Scan_Ptr : Source_Ptr := No_Location;
    --  Current scan pointer location. After a call to Scan, this points
    --  just past the end of the token just scanned.
 
-   Token : Token_Type := No_Token; -- init for -gnatVa
+   Token : Token_Type := No_Token;
    --  Type of current token
 
-   Token_Ptr : Source_Ptr := No_Location; -- init for -gnatVa
+   Token_Ptr : Source_Ptr := No_Location;
    --  Pointer to first character of current token
 
-   Current_Line_Start : Source_Ptr := No_Location; -- init for -gnatVa
+   Current_Line_Start : Source_Ptr := No_Location;
    --  Pointer to first character of line containing current token
 
-   Start_Column : Column_Number := No_Column_Number; -- init for -gnatVa
+   Start_Column : Column_Number := No_Column_Number;
    --  Starting column number (zero origin) of the first non-blank character
    --  on the line containing the current token. This is used for error
    --  recovery circuits which depend on looking at the column line up.
 
-   Type_Token_Location : Source_Ptr := No_Location; -- init for -gnatVa
+   Type_Token_Location : Source_Ptr := No_Location;
    --  Within a type declaration, gives the location of the TYPE keyword that
    --  opened the type declaration. Used in checking the end column of a record
    --  declaration, which can line up either with the TYPE keyword, or with the
    --  start of the line containing the RECORD keyword.
 
-   Checksum : Word := 0; -- init for -gnatVa
+   Checksum : Word := 0;
    --  Used to accumulate a CRC representing the tokens in the source
    --  file being compiled. This CRC includes only program tokens, and
    --  excludes comments.
@@ -399,7 +396,7 @@ package Scans is
    --  limited view of a package, i.e. visible type names and related
    --  tagged indicators.
 
-   First_Non_Blank_Location : Source_Ptr := No_Location; -- init for -gnatVa
+   First_Non_Blank_Location : Source_Ptr := No_Location;
    --  Location of first non-blank character on the line containing the
    --  current token (i.e. the location of the character whose column number
    --  is stored in Start_Column).
diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb
index 5166b4be4e9..f7c03abe49a 100644
--- a/gcc/ada/sem_attr.adb
+++ b/gcc/ada/sem_attr.adb
@@ -1138,7 +1138,7 @@ package body Sem_Attr is
                   --  pointer can be used to modify the variable, and we might
                   --  not detect this, leading to some junk warnings.
 
-                  --  We only do this for source references, since otherwise
+                  --  We do this only for source references, since otherwise
                   --  we can suppress warnings, e.g. from the unrestricted
                   --  access generated for validity checks in -gnatVa mode.
 
diff --git a/gcc/ada/sinput.ads b/gcc/ada/sinput.ads
index af2fec74cf4..febb2ef781b 100644
--- a/gcc/ada/sinput.ads
+++ b/gcc/ada/sinput.ads
@@ -409,8 +409,6 @@ package Sinput is
 
    Current_Source_File : Source_File_Index := No_Source_File;
    --  Source_File table index of source file currently being scanned.
-   --  Initialized so that some tools (such as gprbuild) can be built with
-   --  -gnatVa and pragma Initialize_Scalars without problems.
 
    Current_Source_Unit : Unit_Number_Type := No_Unit;
    --  Unit number of source file currently being scanned. Initialized to
-- 
2.34.1


                 reply	other threads:[~2022-11-14 13:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221114135252.53221-1-poulhies@adacore.com \
    --to=poulhies@adacore.com \
    --cc=duff@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).