PR middle-end/19857
* fold-const.c (fold): Don't optimize (T)(x & cst) to
(T)x & (T)cst if (T)cst overflows.
* convert.c (convert_to_integer) <case POINTER_TYPE>: Pass
TYPE_UNSIGNED (type) as type_for_size's UNSIGNEDP argument.
* gcc.dg/tree-ssa/
20050215-1.c: New test.
* gcc.c-torture/execute/
20050215-1.c: New test.
From-SVN: r95106
+2005-02-16 Jakub Jelinek <jakub@redhat.com>
+
+ PR middle-end/19857
+ * fold-const.c (fold): Don't optimize (T)(x & cst) to
+ (T)x & (T)cst if (T)cst overflows.
+ * convert.c (convert_to_integer) <case POINTER_TYPE>: Pass
+ TYPE_UNSIGNED (type) as type_for_size's UNSIGNEDP argument.
+
2005-02-15 Jeff Law <law@redhat.com>
* gcse.c (blocks_with_calls): New bitmap.
expr = integer_zero_node;
else
expr = fold (build1 (CONVERT_EXPR,
- lang_hooks.types.type_for_size (POINTER_SIZE, 0),
+ lang_hooks.types.type_for_size
+ (POINTER_SIZE, TYPE_UNSIGNED (type)),
expr));
return convert_to_integer (type, expr);
#endif
}
if (change)
- return fold (build2 (BIT_AND_EXPR, type,
- fold_convert (type, and0),
- fold_convert (type, and1)));
+ {
+ tem = build_int_cst_wide (type, TREE_INT_CST_LOW (and1),
+ TREE_INT_CST_HIGH (and1));
+ tem = force_fit_type (tem, 0, TREE_OVERFLOW (and1),
+ TREE_CONSTANT_OVERFLOW (and1));
+ return fold (build2 (BIT_AND_EXPR, type,
+ fold_convert (type, and0), tem));
+ }
}
/* Convert (T1)((T2)X op Y) into (T1)X op Y, for pointer types T1 and
+2005-02-16 Jakub Jelinek <jakub@redhat.com>
+
+ PR middle-end/19857
+ * gcc.dg/tree-ssa/20050215-1.c: New test.
+ * gcc.c-torture/execute/20050215-1.c: New test.
+
2005-02-15 Eric Christopher <echristo@redhat.com>
* gcc.dg/cpp/20050215-1.c: New file.
--- /dev/null
+/* PR middle-end/19857 */
+
+typedef struct { char c[8]; } V
+#ifdef __ELF__
+ __attribute__ ((aligned (8)))
+#endif
+ ;
+typedef __SIZE_TYPE__ size_t;
+V v;
+void abort (void);
+
+int
+main (void)
+{
+ V *w = &v;
+ if (((size_t) ((float *) ((size_t) w & ~(size_t) 3)) % 8) != 0
+ || ((size_t) w & 1))
+ {
+#ifndef __ELF__
+ if (((size_t) &v & 7) == 0)
+#endif
+ abort ();
+ }
+ return 0;
+}
--- /dev/null
+/* PR middle-end/19857 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+int i;
+int foo (void)
+{
+ return i & ~(unsigned int) 3;
+}
+
+/* Make sure the optimizers don't introduce overflow where one
+ did not exist in the original. */
+/* { dg-final { scan-tree-dump-times "-0+4" 0 "optimized"} } */