gimplify: Fix endless recursion on volatile empty type reads/writes [PR101437]
authorJakub Jelinek <jakub@redhat.com>
Thu, 15 Jul 2021 08:17:06 +0000 (10:17 +0200)
committerJakub Jelinek <jakub@redhat.com>
Thu, 15 Jul 2021 08:17:06 +0000 (10:17 +0200)
commitf6dde32b9d487dd6e343d0a1e1d1f60783f5e735
tree6f4e696efc1753282f9320ef0b19b8efe3ea15c7
parentcd6ca96f5d530e4ee07b65ac8b075119ba5bb035
gimplify: Fix endless recursion on volatile empty type reads/writes [PR101437]

Andrew's recent change to optimize away during gimplification not just
assignments of zero sized types, but also assignments of empty types,
caused infinite recursion in the gimplifier.
If such assignment is optimized away, we gimplify separately the to_p
and from_p operands and throw away the result.  When gimplifying the
operand that is volatile, we run into the gimplifier code below, which has
different handling for types with non-BLKmode mode, tries to gimplify
those as vol.N = expr, and for BLKmode just throws those away.
Zero sized types will always have BLKmode and so are fine, but for the
non-BLKmode ones like struct S in the testcase, the vol.N = expr
gimplification will reach again the gimplify_modify_expr code, see it is
assignment of empty type and will gimplify again vol.N separately
(non-volatile, so ok) and expr, on which it will recurse again.

The following patch breaks that infinite recursion by ignoring bare
volatile loads from empty types.
If a volatile load or store for aggregates are supposed to be member-wise
loads or stores, then there are no non-padding members in the empty types that
should be copied and so it is probably ok.

2021-07-15  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/101437
* gimplify.c (gimplify_expr): Throw away volatile reads from empty
types even if they have non-BLKmode TYPE_MODE.

* gcc.c-torture/compile/pr101437.c: New test.
gcc/gimplify.c
gcc/testsuite/gcc.c-torture/compile/pr101437.c [new file with mode: 0644]