public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ARM/heads/morello)] c: Ensure intcap save_expr operands are folded
@ 2023-01-17 10:47 Alex Coplan
0 siblings, 0 replies; only message in thread
From: Alex Coplan @ 2023-01-17 10:47 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:aa8dde4799379b90301785bf0beff2c20935eacc
commit aa8dde4799379b90301785bf0beff2c20935eacc
Author: Alex Coplan <alex.coplan@arm.com>
Date: Mon Dec 12 18:17:10 2022 +0000
c: Ensure intcap save_expr operands are folded
The commment above c_fully_fold notes the following requirement:
Function arguments have already been folded
before calling this function, as have the contents of SAVE_EXPR,
TARGET_EXPR, BIND_EXPR, VA_ARG_EXPR, OBJ_TYPE_REF and
C_MAYBE_CONST_EXPR.
When we recently introduced save_exprs to avoid duplicate side-effects
when forming .REPLACE_ADDRESS_VALUEs in the C front-end, we didn't take
this requirement into account.
As the testcase added with the patch shows, this leads to
c_maybe_const_expr nodes escaping the C front-end, and subsequent ICEs
in the gimplifier. This patch fixes the issue by calling c_fully_fold
prior to calling save_expr on intcap operands.
Diff:
---
gcc/c/c-typeck.c | 6 +++---
gcc/testsuite/c-c++-common/torture/intptr-fold.c | 10 ++++++++++
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 1fcaa7dbebb..817b8ac844b 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -4401,7 +4401,7 @@ build_unary_op (location_t location, enum tree_code code, tree xarg,
default:
intcap = unary_op_get_intcap_provenance (arg);
if (arg == intcap)
- intcap = arg = save_expr (arg);
+ intcap = arg = save_expr (c_fully_fold (arg, false, NULL));
arg = drop_capability (arg);
}
}
@@ -11970,9 +11970,9 @@ build_binary_op_1 (location_t location, enum tree_code code,
c + cv --> REPLACE_ADDRESS_VALUE (c, (non-cap type) c + cv)
we need to avoid evaluating c twice. */
if (intcap == op0)
- intcap = op0 = save_expr (op0);
+ intcap = op0 = save_expr (c_fully_fold (op0, false, NULL));
else if (intcap == op1)
- intcap = op1 = save_expr (op1);
+ intcap = op1 = save_expr (c_fully_fold (op1, false, NULL));
if (common_ic_type)
{
diff --git a/gcc/testsuite/c-c++-common/torture/intptr-fold.c b/gcc/testsuite/c-c++-common/torture/intptr-fold.c
new file mode 100644
index 00000000000..f62b398ae17
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/torture/intptr-fold.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* This would ICE in the gimplifier on capability targets due to
+ c_maybe_const_expr escaping the C front-end. */
+typedef __INTPTR_TYPE__ T;
+typedef struct {
+ T a;
+} S;
+T f(T x) {
+ return -(x ? ((S *)x)->a : x);
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-01-17 10:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-17 10:47 [gcc(refs/vendors/ARM/heads/morello)] c: Ensure intcap save_expr operands are folded Alex Coplan
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).