public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-2320] gimplify: Fix endless recursion on volatile empty type reads/writes [PR101437]
@ 2021-07-15 8:17 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2021-07-15 8:17 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:f6dde32b9d487dd6e343d0a1e1d1f60783f5e735
commit r12-2320-gf6dde32b9d487dd6e343d0a1e1d1f60783f5e735
Author: Jakub Jelinek <jakub@redhat.com>
Date: Thu Jul 15 10:17:06 2021 +0200
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.
Diff:
---
gcc/gimplify.c | 3 ++-
gcc/testsuite/gcc.c-torture/compile/pr101437.c | 29 ++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 75a4a9d59fd..93a2121fea1 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -15060,7 +15060,8 @@ gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
*expr_p = NULL;
}
else if (COMPLETE_TYPE_P (TREE_TYPE (*expr_p))
- && TYPE_MODE (TREE_TYPE (*expr_p)) != BLKmode)
+ && TYPE_MODE (TREE_TYPE (*expr_p)) != BLKmode
+ && !is_empty_type (TREE_TYPE (*expr_p)))
{
/* Historically, the compiler has treated a bare reference
to a non-BLKmode volatile lvalue as forcing a load. */
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr101437.c b/gcc/testsuite/gcc.c-torture/compile/pr101437.c
new file mode 100644
index 00000000000..96e7df89046
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr101437.c
@@ -0,0 +1,29 @@
+/* PR middle-end/101437 */
+
+struct S { int : 1; };
+
+void
+foo (volatile struct S *p)
+{
+ struct S s = {};
+ *p = s;
+}
+
+void
+bar (volatile struct S *p)
+{
+ *p;
+}
+
+void
+baz (volatile struct S *p)
+{
+ struct S s;
+ s = *p;
+}
+
+void
+qux (volatile struct S *p, volatile struct S *q)
+{
+ *p = *q;
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-07-15 8:17 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-15 8:17 [gcc r12-2320] gimplify: Fix endless recursion on volatile empty type reads/writes [PR101437] Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).