diff mbox series

[COMMITTED,20/30] ada: Fix bug in resolution of Ghost_Predicate

Message ID 20240801151738.400796-20-poulhies@adacore.com
State New
Headers show
Series [COMMITTED,01/30] ada: Remove obsolete workaround | expand

Commit Message

Marc Poulhiès Aug. 1, 2024, 3:17 p.m. UTC
From: Bob Duff <duff@adacore.com>

This patch fixes a failure of name resolution when
a range attribute reference appears in a Ghost_Predicate
and the ghost policy is Ignore.

gcc/ada/

	* sem_ch13.adb (Add_Predicate): Remove the premature "return;".
	Ghost code needs to be processed by later code in this procedure
	even when ignored; otherwise the second pass of name resolution
	fails much later. However, protect Set_SCO_Pragma_Enabled and
	Add_Condition with "if not Is_Ignored_Ghost_Pragma"; these parts
	should not happen if the ghost code is Ignored.
	* libgnat/interfac__2020.ads (Unsigned_8): Minor reformatting.
	* libgnat/interfac.ads (IEEE_Extended_Float): Minor comment
	improvement.

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

---
 gcc/ada/libgnat/interfac.ads       |  2 +-
 gcc/ada/libgnat/interfac__2020.ads |  1 +
 gcc/ada/sem_ch13.adb               | 12 +++++++-----
 3 files changed, 9 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/gcc/ada/libgnat/interfac.ads b/gcc/ada/libgnat/interfac.ads
index b57264deb26..fe130d016ba 100644
--- a/gcc/ada/libgnat/interfac.ads
+++ b/gcc/ada/libgnat/interfac.ads
@@ -62,7 +62,7 @@  is
    --  such as SPARK or CodePeer. In the normal case Long_Long_Integer is
    --  always 64-bits so we get the desired 64-bit type.
 
-   type Unsigned_8  is mod 2 ** 8;
+   type Unsigned_8 is mod 2 ** 8;
    for Unsigned_8'Size use  8;
 
    type Unsigned_16 is mod 2 ** 16;
diff --git a/gcc/ada/libgnat/interfac__2020.ads b/gcc/ada/libgnat/interfac__2020.ads
index 0b5cc7d4339..cb20f34b0d7 100644
--- a/gcc/ada/libgnat/interfac__2020.ads
+++ b/gcc/ada/libgnat/interfac__2020.ads
@@ -227,6 +227,7 @@  is
    --  Note: it is harmless, and explicitly permitted, to include additional
    --  types in interfaces, so it is not wrong to have IEEE_Extended_Float
    --  defined even if the extended format is not available.
+   --  See RM-B.2(11).
 
    type IEEE_Extended_Float is new Long_Long_Float;
 
diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb
index b903381e5de..171e516bf3d 100644
--- a/gcc/ada/sem_ch13.adb
+++ b/gcc/ada/sem_ch13.adb
@@ -10218,12 +10218,12 @@  package body Sem_Ch13 is
 
             if Is_Ignored_Ghost_Pragma (Prag) then
                Add_Condition (New_Occurrence_Of (Standard_True, Sloc (Prag)));
-               return;
-            end if;
 
-            --  Mark corresponding SCO as enabled
+            else
+               --  Mark corresponding SCO as enabled
 
-            Set_SCO_Pragma_Enabled (Sloc (Prag));
+               Set_SCO_Pragma_Enabled (Sloc (Prag));
+            end if;
 
             --  Extract the arguments of the pragma
 
@@ -10257,7 +10257,9 @@  package body Sem_Ch13 is
 
                   --  "and"-in the Arg2 condition to evolving expression
 
-                  Add_Condition (Arg2_Copy);
+                  if not Is_Ignored_Ghost_Pragma (Prag) then
+                     Add_Condition (Arg2_Copy);
+                  end if;
                end;
             end if;
          end Add_Predicate;