[Ada] Disable wrong computation of offsets within multidimensional arrays
authorPiotr Trojanek <trojanek@adacore.com>
Fri, 26 Mar 2021 08:36:49 +0000 (09:36 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 21 Jun 2021 10:45:04 +0000 (06:45 -0400)
gcc/ada/

* sem_util.adb (Indexed_Component_Bit_Offset): Return an unknown
offset for components within multidimensional arrays; remove
redundant parens.

gcc/ada/sem_util.adb

index 2e102b934970d18322c1207e9c8b66087d64b3d8..44a568404ad1decf0e3e6e505bfcea48854d2b32 100644 (file)
@@ -14827,6 +14827,12 @@ package body Sem_Util is
          return No_Uint;
       end if;
 
+      --  Do not attempt to compute offsets within multi-dimensional arrays
+
+      if Present (Next_Index (Ind)) then
+         return No_Uint;
+      end if;
+
       if Nkind (Ind) = N_Subtype_Indication then
          Ind := Constraint (Ind);
 
@@ -14843,7 +14849,7 @@ package body Sem_Util is
 
       --  Return the scaled offset
 
-      return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound ((Ind))));
+      return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound (Ind)));
    end Indexed_Component_Bit_Offset;
 
    -----------------------------