diff mbox series

[Ada] Fix excessive check for alignment of overlaying objects

Message ID 20210705131408.GA2222424@adacore.com
State New
Headers show
Series [Ada] Fix excessive check for alignment of overlaying objects | expand

Commit Message

Pierre-Marie de Rodat July 5, 2021, 1:14 p.m. UTC
When generating alignment checks for Address representation clauses we
optimized them away for clauses like:

  for X'Address use Arr (1)'Address;
  for X'Address use Rec.C'Address;

but not:

  for X'Address use Obj'Address;

even though the alignment of Obj is known.

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

gcc/ada/

	* sem_util.adb (Has_Compatible_Alignment_Internal): If the
	prefix of the Address expression is an entire object with a
	known alignment, then skip checks related to its size.
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
@@ -11939,6 +11939,7 @@  package body Sem_Util is
                   elsif Is_Entity_Name (Expr)
                     and then Known_Alignment (Entity (Expr))
                   then
+                     Offs := Uint_0;
                      ExpA := Alignment (Entity (Expr));
 
                   --  Otherwise, we can use the alignment of the type of Expr
@@ -11961,9 +11962,9 @@  package body Sem_Util is
                      Set_Result (Known_Incompatible);
                   end if;
 
-                  --  If Expr is not a piece of a larger object, see if size
-                  --  is given. If so, check that it is not too small for the
-                  --  required alignment.
+                  --  If Expr is a component or an entire object with a known
+                  --  alignment, then we are fine. Otherwise, if its size is
+                  --  known, it must be big enough for the required alignment.
 
                   if Offs /= No_Uint then
                      null;
@@ -11982,7 +11983,7 @@  package body Sem_Util is
                   end if;
 
                   --  If we got a size, see if it is a multiple of the Obj
-                  --  alignment, if not, then the alignment cannot be
+                  --  alignment; if not, then the alignment cannot be
                   --  acceptable, since the size is always a multiple of the
                   --  alignment.