Routine Indexed_Component_Bit_Offset is meant to return the first bit
position of an array component, but it only examined the first index
expression and necessarily produced wrong results for multidimensional
arrays.
Since this routine is only used for warnings, it is safe to simply
disable this wrong code and behave just like if the offsets within
a multidimensional array would not be known at compile time.
Tested on x86_64-pc-linux-gnu, committed on trunk
gcc/ada/
* sem_util.adb (Indexed_Component_Bit_Offset): Return an unknown
offset for components within multidimensional arrays; remove
redundant parens.
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
@@ -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;
-----------------------------