diff mbox series

[Ada] Fix handling of PATs

Message ID 20210506075812.GA125586@adacore.com
State New
Headers show
Series [Ada] Fix handling of PATs | expand

Commit Message

Pierre-Marie de Rodat May 6, 2021, 7:58 a.m. UTC
When trying to compare two fields, one that's a packed array of known
length and one that's a packed array of unknown length, Expand_Packed_Eq
converts each side of the equality to its packed array type
and then says that's enough if the types are modular integer types.
That's correct, however, only if they're the same PATs.

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


	* exp_pakd.adb (Expand_Packed_Eq): Fix handling of PATs.
diff mbox series


diff --git a/gcc/ada/exp_pakd.adb b/gcc/ada/exp_pakd.adb
--- a/gcc/ada/exp_pakd.adb
+++ b/gcc/ada/exp_pakd.adb
@@ -1909,9 +1909,10 @@  package body Exp_Pakd is
       --  where PAT is the packed array type. This works fine, since in the
       --  modular case we guarantee that the unused bits are always zeroes.
       --  We do have to compare the lengths because we could be comparing
-      --  two different subtypes of the same base type.
+      --  two different subtypes of the same base type. We can only do this
+      --  if the PATs on both sides are the same.
-      if Is_Modular_Integer_Type (PAT) then
+      if Is_Modular_Integer_Type (PAT) and then PAT = Etype (R) then
          Rewrite (N,
            Make_And_Then (Loc,
              Left_Opnd =>