diff mbox series

[Ada] Skip overlay checks on protected components with expansion disabled

Message ID 20210621110533.GA41733@adacore.com
State New
Headers show
Series [Ada] Skip overlay checks on protected components with expansion disabled | expand

Commit Message

Pierre-Marie de Rodat June 21, 2021, 11:05 a.m. UTC
Routine Find_Overlaid_Entity collects entire objects from prefixes of
attribute Address is overlay specifications. The alignment of those
entire objects are then examined in Validate_Address_Clauses.

However, Find_Overlaid_Entity wrongly collects protected components (and
discriminants of concurrent units), even though they do not represent
entire objects and don't have alignment specified, which causes crashes.

This is only a problem when expansion is disabled, e.g. in GNATprove
mode or when switch -gnatc is used. When expansion is enabled,
references to protected components are rewritten into references to
renamings of components of the implicit concurrent type record.

Since this only affects warnings and not legality checks, it is harmless
to ignore such objects in non-standard compilation modes.

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

gcc/ada/

	* sem_util.adb (Find_Overlaid_Entity): Ignore references to
	components and discriminants.
diff mbox series

Patch

diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -9437,6 +9437,18 @@  package body Sem_Util is
 
          if Is_Entity_Name (Expr) then
             Ent := Entity (Expr);
+
+            --  If expansion is disabled, then we might see an entity of a
+            --  protected component or of a discriminant of a concurrent unit.
+            --  Ignore such entities, because further warnings for overlays
+            --  expect this routine to only collect entities of entire objects.
+
+            if Ekind (Ent) in E_Component | E_Discriminant then
+               pragma Assert
+                 (not Expander_Active
+                  and then Is_Concurrent_Type (Scope (Ent)));
+               Ent := Empty;
+            end if;
             return;
 
          --  Check for components