[COMMITTED] ada: Fix Valid_Scalars attribute applied to types from limited with

Message ID 20230718131311.80670-1-poulhies@adacore.com
State Accepted
Headers
Series [COMMITTED] ada: Fix Valid_Scalars attribute applied to types from limited with |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Marc Poulhiès July 18, 2023, 1:13 p.m. UTC
  From: Eric Botcazou <ebotcazou@adacore.com>

The attribute is wrongly computed as always True because, unlike for e.g.
private types, Validated_View does not look through the limited view.

gcc/ada/

	* sem_util.ads (Validated_View): Document enhanced behavior.
	* sem_util.adb (Validated_View): Return the nonlimited view, if any,
	of types coming from a limited with.

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

---
 gcc/ada/sem_util.adb | 7 +++++++
 gcc/ada/sem_util.ads | 4 ++--
 2 files changed, 9 insertions(+), 2 deletions(-)
  

Patch

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 821aacf1ccb..222fd72a061 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -29231,6 +29231,13 @@  package body Sem_Util is
             return Typ;
          end if;
 
+      elsif From_Limited_With (Typ) then
+         if Has_Non_Limited_View (Typ) then
+            return Validated_View (Non_Limited_View (Typ));
+         else
+            return Typ;
+         end if;
+
       else
          return Typ;
       end if;
diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads
index 3751fb73702..7fc77de2b8a 100644
--- a/gcc/ada/sem_util.ads
+++ b/gcc/ada/sem_util.ads
@@ -3331,8 +3331,8 @@  package Sem_Util is
    function Validated_View (Typ : Entity_Id) return Entity_Id;
    --  Obtain the "validated view" of arbitrary type Typ which is suitable for
    --  verification by attribute 'Valid_Scalars. This view is the type itself
-   --  or its full view while stripping away concurrency, derivations, and
-   --  privacy.
+   --  or its full view or nonlimited view, while stripping away concurrency,
+   --  derivations, and privacy.
 
    function Visible_Ancestors (Typ : Entity_Id) return Elist_Id;
    --  [Ada 2012:AI-0125-1]: Collect all the visible parents and progenitors