https://gcc.gnu.org/g:c328b54f15d81b021bb3ae3084f49b61cd52b1d3

commit r16-1142-gc328b54f15d81b021bb3ae3084f49b61cd52b1d3
Author: squirek <squi...@adacore.com>
Date:   Thu Jan 16 17:09:49 2025 +0000

    ada: Spurious accessibility error with -gnatc
    
    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

Diff:
---
 gcc/ada/accessibility.adb | 6 +++---
 gcc/ada/opt.ads           | 4 ++++
 gcc/ada/switch-c.adb      | 1 +
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/accessibility.adb b/gcc/ada/accessibility.adb
index 200f892a96f0..0b8d3f7746d7 100644
--- a/gcc/ada/accessibility.adb
+++ b/gcc/ada/accessibility.adb
@@ -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;
 
diff --git a/gcc/ada/opt.ads b/gcc/ada/opt.ads
index 687d1ed8836a..87ce3a1d4639 100644
--- a/gcc/ada/opt.ads
+++ b/gcc/ada/opt.ads
@@ -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
diff --git a/gcc/ada/switch-c.adb b/gcc/ada/switch-c.adb
index 6344a0b3a3cf..1e54340d5202 100644
--- a/gcc/ada/switch-c.adb
+++ b/gcc/ada/switch-c.adb
@@ -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)

Reply via email to