Commit 02614448 by Ian Lance Taylor Committed by Ian Lance Taylor

re PR middle-end/49705 (-Wstrict-overflow should not diagnose unevaluated expressions)

gcc/c-family:
	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:
	PR middle-end/49705
	* gcc.dg/pr49705.c: New test.

From-SVN: r176591
parent 1f1c0dbd
2011-07-21 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.
2011-07-20 Jason Merrill <jason@redhat.com> 2011-07-20 Jason Merrill <jason@redhat.com>
PR c++/6709 (DR 743) PR c++/6709 (DR 743)
......
...@@ -963,6 +963,32 @@ fix_string_type (tree value) ...@@ -963,6 +963,32 @@ fix_string_type (tree value)
return 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 /* Fully fold EXPR, an expression that was not folded (beyond integer
constant expressions and null pointer constants) when being built constant expressions and null pointer constants) when being built
up. If IN_INIT, this is in a static initializer and certain up. If IN_INIT, this is in a static initializer and certain
...@@ -1029,7 +1055,7 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands, ...@@ -1029,7 +1055,7 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands,
bool op0_const = true, op1_const = true, op2_const = true; bool op0_const = true, op1_const = true, op2_const = true;
bool op0_const_self = true, op1_const_self = true, op2_const_self = true; bool op0_const_self = true, op1_const_self = true, op2_const_self = true;
bool nowarning = TREE_NO_WARNING (expr); bool nowarning = TREE_NO_WARNING (expr);
int unused_p; bool unused_p;
/* This function is not relevant to C++ because C++ folds while /* This function is not relevant to C++ because C++ folds while
parsing, and may need changes to be correct for C++ when C++ parsing, and may need changes to be correct for C++ when C++
...@@ -1278,10 +1304,10 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands, ...@@ -1278,10 +1304,10 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands,
unused_p = (op0 == (code == TRUTH_ANDIF_EXPR unused_p = (op0 == (code == TRUTH_ANDIF_EXPR
? truthvalue_false_node ? truthvalue_false_node
: truthvalue_true_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); op1 = c_fully_fold_internal (op1, in_init, &op1_const, &op1_const_self);
STRIP_TYPE_NOPS (op1); STRIP_TYPE_NOPS (op1);
c_inhibit_evaluation_warnings -= unused_p; c_enable_warnings (unused_p);
if (op0 != orig_op0 || op1 != orig_op1 || in_init) if (op0 != orig_op0 || op1 != orig_op1 || in_init)
ret = in_init ret = in_init
...@@ -1313,15 +1339,15 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands, ...@@ -1313,15 +1339,15 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands,
op0 = c_fully_fold_internal (op0, in_init, &op0_const, &op0_const_self); op0 = c_fully_fold_internal (op0, in_init, &op0_const, &op0_const_self);
STRIP_TYPE_NOPS (op0); 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); op1 = c_fully_fold_internal (op1, in_init, &op1_const, &op1_const_self);
STRIP_TYPE_NOPS (op1); 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); op2 = c_fully_fold_internal (op2, in_init, &op2_const, &op2_const_self);
STRIP_TYPE_NOPS (op2); 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) if (op0 != orig_op0 || op1 != orig_op1 || op2 != orig_op2)
ret = fold_build3_loc (loc, code, TREE_TYPE (expr), op0, op1, op2); ret = fold_build3_loc (loc, code, TREE_TYPE (expr), op0, op1, op2);
......
2011-07-21 Ian Lance Taylor <iant@google.com>
PR middle-end/49705
* gcc.dg/pr49705.c: New test.
2011-07-21 Uros Bizjak <ubizjak@gmail.com> 2011-07-21 Uros Bizjak <ubizjak@gmail.com>
* lib/target-supports.exp (check_avx_os_support_available): New. * lib/target-supports.exp (check_avx_os_support_available): New.
......
/* { 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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment