]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Spurious accessibility error with -gnatc
authorsquirek <squirek@adacore.com>
Thu, 16 Jan 2025 17:09:49 +0000 (17:09 +0000)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 5 Jun 2025 08:18:35 +0000 (10:18 +0200)
The patch fixes an issue in the compiler whereby a spurious accessibility
error gets generated in semantic checking mode (-gnatc) when an explicitly
aliased formal gets used as an actual for an access disriminant in a return
object.

gcc/ada/ChangeLog:

* accessibility.adb (Check_Return_Construct_Accessibility):
Disable check generation when we are only checking semantics.
* opt.ads: Add new flag for -gnatc mode
* switch-c.adb (Scan_Front_End_Switches): Set flag for -gnatc mode

gcc/ada/accessibility.adb
gcc/ada/opt.ads
gcc/ada/switch-c.adb

index 200f892a96f097e850b532c9ca2ab1bb7fdb8c13..0b8d3f7746d7573fbec483b8419f7fb32609ff5e 100644 (file)
@@ -1648,7 +1648,7 @@ package body Accessibility is
            --  accessibility of result), and constant folding can occur and
            --  lead to spurious errors.
 
-           and then Operating_Mode /= Check_Semantics
+           and then not Check_Semantics_Only_Mode
          then
             --  Generate a dynamic check based on the extra accessibility of
             --  the result or the scope of the current function.
@@ -1691,8 +1691,8 @@ package body Accessibility is
               and then Entity (Check_Cond) = Standard_True
             then
                Error_Msg_N
-                 ("access discriminant in return object would be a dangling"
-                  & " reference", Return_Stmt);
+                 ("access discriminant in return object could be a dangling"
+                  & " reference??", Return_Stmt);
             end if;
          end if;
 
index 687d1ed8836a1b461c940df7bf4086a6d9dacab4..87ce3a1d4639dff045c9e6ec486b4b102aeb1325 100644 (file)
@@ -308,6 +308,10 @@ package Opt is
    --  GNATMAKE
    --  Set to True to check readonly files during the make process
 
+   Check_Semantics_Only_Mode : Boolean := False;
+   --  GNATMAKE
+   --  Set to True when -gnatc is present to only perform semantic checking.
+
    Check_Source_Files : Boolean := True;
    --  GNATBIND, GNATMAKE
    --  Set to True to enable consistency checking for any source files that
index 6344a0b3a3cf674a4dce53e0ff8ca64830e07d21..1e54340d5202a8f97d107834b0c7b333e8ee4d7e 100644 (file)
@@ -335,6 +335,7 @@ package body Switch.C is
                end if;
 
                Ptr := Ptr + 1;
+               Check_Semantics_Only_Mode := True;
                Operating_Mode := Check_Semantics;
 
             --  -gnatC (Generate CodePeer information)