[Ada] Fix validity checking for class-wide objects

Message ID 20200619082833.GA31193@adacore.com
State New
Headers show
Series
  • [Ada] Fix validity checking for class-wide objects
Related show

Commit Message

Pierre-Marie de Rodat June 19, 2020, 8:28 a.m.
When applying 'Valid_Scalars attribute to a class-wide object (either
explicitly or as a result of a command line switch like -gnateV), we
must strip away type privacy.

Note: this is just a minimal fix to avoid a crash. Attribute
'Valid_Scalars is not really working as expected on tagged types,
especially with private derivations and type extensions.

Tested on x86_64-pc-linux-gnu, committed on trunk

2020-06-19  Piotr Trojanek  <trojanek@adacore.com>

gcc/ada/

	* exp_attr.adb (Build_Record_VS_Func): Strip privacy and type
	derivation from the root type when 'Valid_Scalars is applied to
	a class-wide type.

Patch

--- gcc/ada/exp_attr.adb
+++ gcc/ada/exp_attr.adb
@@ -737,7 +737,7 @@  package body Exp_Attr is
       --  Use the root type when dealing with a class-wide type
 
       if Is_Class_Wide_Type (Typ) then
-         Typ := Root_Type (Typ);
+         Typ := Validated_View (Root_Type (Typ));
       end if;
 
       Typ_Decl := Declaration_Node (Typ);