This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH RFA: Disable -Wstrict-overflow for unevaluated expressions
- From: Ian Lance Taylor <iant at google dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 12 Jul 2011 15:45:21 -0700
- Subject: PATCH RFA: Disable -Wstrict-overflow for unevaluated expressions
This patch to the C frontend disables warnings about -Wstrict-overflow
when handling expressions which will not be evaluated. This fixes PR
49705.
Bootstrapped and tested on x86_64-unknown-linux-gnu.
OK for mainline?
Ian
gcc/c-family:
2011-07-12 Ian Lance Taylor <iant@google.com>
PR middle-end/49705
* c-common.c (c_disable_warnings): New static function.
(c_enable_warnings): New static function.
(c_fully_fold_internal): Change local unused_p to bool. Call
c_disable_warnings and c_enable_warnings rather than change
c_inhibit_evaluation_warnings.
gcc/testsuite:
2011-07-12 Ian Lance Taylor <iant@google.com>
PR middle-end/49705
* gcc.dg/pr49705.c: New test.
Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c (revision 175665)
+++ gcc/c-family/c-common.c (working copy)
@@ -963,6 +963,32 @@ fix_string_type (tree value)
return value;
}
+/* If DISABLE is true, stop issuing warnings. This is used when
+ parsing code that we know will not be executed. This function may
+ be called multiple times, and works as a stack. */
+
+static void
+c_disable_warnings (bool disable)
+{
+ if (disable)
+ {
+ ++c_inhibit_evaluation_warnings;
+ fold_defer_overflow_warnings ();
+ }
+}
+
+/* If ENABLE is true, reenable issuing warnings. */
+
+static void
+c_enable_warnings (bool enable)
+{
+ if (enable)
+ {
+ --c_inhibit_evaluation_warnings;
+ fold_undefer_and_ignore_overflow_warnings ();
+ }
+}
+
/* Fully fold EXPR, an expression that was not folded (beyond integer
constant expressions and null pointer constants) when being built
up. If IN_INIT, this is in a static initializer and certain
@@ -1029,7 +1055,7 @@ c_fully_fold_internal (tree expr, bool i
bool op0_const = true, op1_const = true, op2_const = true;
bool op0_const_self = true, op1_const_self = true, op2_const_self = true;
bool nowarning = TREE_NO_WARNING (expr);
- int unused_p;
+ bool unused_p;
/* This function is not relevant to C++ because C++ folds while
parsing, and may need changes to be correct for C++ when C++
@@ -1278,10 +1304,10 @@ c_fully_fold_internal (tree expr, bool i
unused_p = (op0 == (code == TRUTH_ANDIF_EXPR
? truthvalue_false_node
: truthvalue_true_node));
- c_inhibit_evaluation_warnings += unused_p;
+ c_disable_warnings (unused_p);
op1 = c_fully_fold_internal (op1, in_init, &op1_const, &op1_const_self);
STRIP_TYPE_NOPS (op1);
- c_inhibit_evaluation_warnings -= unused_p;
+ c_enable_warnings (unused_p);
if (op0 != orig_op0 || op1 != orig_op1 || in_init)
ret = in_init
@@ -1313,15 +1339,15 @@ c_fully_fold_internal (tree expr, bool i
op0 = c_fully_fold_internal (op0, in_init, &op0_const, &op0_const_self);
STRIP_TYPE_NOPS (op0);
- c_inhibit_evaluation_warnings += (op0 == truthvalue_false_node);
+ c_disable_warnings (op0 == truthvalue_false_node);
op1 = c_fully_fold_internal (op1, in_init, &op1_const, &op1_const_self);
STRIP_TYPE_NOPS (op1);
- c_inhibit_evaluation_warnings -= (op0 == truthvalue_false_node);
+ c_enable_warnings (op0 == truthvalue_false_node);
- c_inhibit_evaluation_warnings += (op0 == truthvalue_true_node);
+ c_disable_warnings (op0 == truthvalue_true_node);
op2 = c_fully_fold_internal (op2, in_init, &op2_const, &op2_const_self);
STRIP_TYPE_NOPS (op2);
- c_inhibit_evaluation_warnings -= (op0 == truthvalue_true_node);
+ c_enable_warnings (op0 == truthvalue_true_node);
if (op0 != orig_op0 || op1 != orig_op1 || op2 != orig_op2)
ret = fold_build3_loc (loc, code, TREE_TYPE (expr), op0, op1, op2);
Index: gcc/testsuite/gcc.dg/pr49705.c
===================================================================
--- gcc/testsuite/gcc.dg/pr49705.c (revision 0)
+++ gcc/testsuite/gcc.dg/pr49705.c (revision 0)
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wstrict-overflow" } */
+
+struct glyph
+{
+ long foo, bar, baz;
+};
+
+extern int fatal (char const *, int, int);
+
+int
+check_image_width (int width, int height)
+{
+ if ((((((0 * (0 * 2 + width) - 1) < 0) ? - (~ (0 * (0 * 2 + width) + 0) == -1) - ((((0 * (0 * 2 + width) + 1) << (sizeof ((0 * 2 + width) + 0) * 8 - 2)) - 1) * 2 + 1) : (0 * (0 * 2 + width) + 0))) < 0 ? (2 < 0 ? width < ((((0 * (0 * 2 + width) - 1) < 0) ? - (~ (0 * (0 * 2 + width) + 0) == -1) - ((((0 * (0 * 2 + width) + 1) << (sizeof ((0 * 2 + width) + 0) * 8 - 2)) - 1) * 2 + 1) : (0 * (0 * 2 + width) + 0))) - 2 : ((((0 * (0 * 2 + width) - 1) < 0) ? ((((0 * (0 * 2 + width) + 1) << (sizeof ((0 * 2 + width) + 0) * 8 - 2)) - 1) * 2 + 1) : (0 * (0 * 2 + width) - 1))) - 2 < width) : width < 0 ? 2 <= width + 2 : 2 < 0 ? width <= width + 2 : width + 2 < 2)
+ || ((((((0 * (0 * height + (width + 2)) - 1) < 0) ? - (~ (0 * (0 * height + (width + 2)) + 0) == -1) - ((((0 * (0 * height + (width + 2)) + 1) << (sizeof ((0 * height + (width + 2)) + 0) * 8 - 2)) - 1) * 2 + 1) : (0 * (0 * height + (width + 2)) + 0))) == 0 && (((width + 2) < 0 && 0 < height) || (height < 0 && 0 < (width + 2)))) || (height < 0 ? ((width + 2) < 0 ? (width + 2) < ((((0 * (0 * height + (width + 2)) - 1) < 0) ? ((((0 * (0 * height + (width + 2)) + 1) << (sizeof ((0 * height + (width + 2)) + 0) * 8 - 2)) - 1) * 2 + 1) : (0 * (0 * height + (width + 2)) - 1))) / height : height == -1 ? 0 : ((((0 * (0 * height + (width + 2)) - 1) < 0) ? - (~ (0 * (0 * height + (width + 2)) + 0) == -1) - ((((0 * (0 * height + (width + 2)) + 1) << (sizeof ((0 * height + (width + 2)) + 0) * 8 - 2)) - 1) * 2 + 1) : (0 * (0 * height + (width + 2)) + 0))) / height < (width + 2)) : height == 0 ? 0 : ((width + 2) < 0 ? (width + 2) < ((((0 * (0 * height + (width + 2)) - 1) < 0) ? - (~ (0 * (0 * height + (width + 2)) + 0) == -1) - ((((0 * (0 * height + (width + 2)) + 1) << (sizeof ((0 * height + (width + 2)) + 0) * 8 - 2)) - 1) * 2 + 1) : (0 * (0 * height + (width + 2)) + 0))) / height : ((((0 * (0 * height + (width + 2)) - 1) < 0) ? ((((0 * (0 * height + (width + 2)) + 1) << (sizeof ((0 * height + (width + 2)) + 0) * 8 - 2)) - 1) * 2 + 1) : (0 * (0 * height + (width + 2)) - 1))) / height < (width + 2))))
+ || ((9223372036854775807L < 18446744073709551615UL ? 9223372036854775807L : 18446744073709551615UL) / sizeof (struct glyph)
+ < (width + 2) * height))
+ fatal ("screen size %dx%d too big", width, height);
+}