aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fold-const.c2
-rw-r--r--gcc/testsuite/gcc.dg/pr101858.c9
2 files changed, 11 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 7dcecc9..ff23f12 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 0000000..61fcca6
--- /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;
+}