public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-2850] middle-end/101858 - avoid shift of pointer in folding
@ 2021-08-11 12:01 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2021-08-11 12:01 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:d7e91f4894f6a1a2daeec5cbe1e912bb896b9f7a
commit r12-2850-gd7e91f4894f6a1a2daeec5cbe1e912bb896b9f7a
Author: Richard Biener <rguenther@suse.de>
Date: Wed Aug 11 10:26:18 2021 +0200
middle-end/101858 - avoid shift of pointer in folding
This makes sure to not generate a shift of pointer types in
simplification of X < (cast) (1 << Y).
2021-08-11 Richard Biener <rguenther@suse.de>
PR middle-end/101858
* fold-const.c (fold_binary_loc): Guard simplification
of X < (cast) (1 << Y) to integer types.
* gcc.dg/pr101858.c: New testcase.
Diff:
---
gcc/fold-const.c | 2 ++
gcc/testsuite/gcc.dg/pr101858.c | 9 +++++++++
2 files changed, 11 insertions(+)
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 7dcecc9a5c0..ff23f12f33c 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -12497,6 +12497,8 @@ fold_binary_loc (location_t loc, enum tree_code code, tree type,
we can't optimize this. E.g. (unsigned long long) (1 << Y) for Y
31 might be 0xffffffff80000000. */
if ((code == LT_EXPR || code == GE_EXPR)
+ && (INTEGRAL_TYPE_P (TREE_TYPE (arg0))
+ || VECTOR_INTEGER_TYPE_P (TREE_TYPE (arg0)))
&& TYPE_UNSIGNED (TREE_TYPE (arg0))
&& CONVERT_EXPR_P (arg1)
&& TREE_CODE (TREE_OPERAND (arg1, 0)) == LSHIFT_EXPR
diff --git a/gcc/testsuite/gcc.dg/pr101858.c b/gcc/testsuite/gcc.dg/pr101858.c
new file mode 100644
index 00000000000..61fcca60982
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr101858.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-w" } */
+
+int foo(int a)
+{
+ if (a < (int*)((__INTPTR_TYPE__)1 << a))
+ a = 0;
+ return a;
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-08-11 12:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-11 12:01 [gcc r12-2850] middle-end/101858 - avoid shift of pointer in folding Richard Biener
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).