Fix artificial overflow during GENERIC folding
commit3fa303becdc877a77e67e04401a50246dd05bd81
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 29 May 2023 07:45:57 +0000 (29 09:45 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Mon, 29 May 2023 09:13:08 +0000 (29 11:13 +0200)
tree59900ba53dca1cb3243791b1ac1ac81f1f994ac8
parent6c2b2de098af7d3bf42126301438b70ad1279bcd
Fix artificial overflow during GENERIC folding

The Ada compiler gives a bogus warning:
storage_offset1.ads:16:52: warning: Constraint_Error will be raised at run
time [enabled by default]

Ironically enough, this occurs because of an intermediate conversion to an
unsigned type which is supposed to hide overflows but is counter-productive
for constants because TREE_OVERFLOW is always set for them, so it ends up
setting a bogus TREE_OVERFLOW when converting back to the original type.

The fix simply redirects INTEGER_CSTs to the other, direct path without the
intermediate conversion to the unsigned type.

gcc/
* match.pd ((T)P - (T)(P + A) -> -(T) A): Avoid artificial overflow
on constants.

gcc/testsuite/
* gnat.dg/specs/storage_offset1.ads: New test.
gcc/match.pd
gcc/testsuite/gnat.dg/specs/storage_offset1.ads [new file with mode: 0644]