public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/49705] New: -Wstrict-overflow should not diagnose unevaluated expressions
@ 2011-07-11 18:18 eggert at gnu dot org
2011-07-12 8:57 ` [Bug middle-end/49705] " rguenth at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: eggert at gnu dot org @ 2011-07-11 18:18 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49705
Summary: -Wstrict-overflow should not diagnose unevaluated
expressions
Product: gcc
Version: 4.6.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: eggert@gnu.org
Host: x86_64-unknown-linux-gnu
Target: x86_64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu
I ran into this problem when compiling a test version of Emacs.
Here's a stripped-down version of the problem:
int
check_image_width (int width)
{
return (1 || width <= width + 2);
}
When compiled with "gcc -c -Wstrict-overflow -O2 t.c" the diagnostic is:
t.c:4:3: warning: assuming signed overflow does not occur when assuming that
(X + c) >= X is always true [-Wstrict-overflow]
This diagnostic is wrong, as the expression in question (width <=
width + 2) is unreachable. In the original source code the
expression is unreachable because the code is carefully checking for
integer overflow.
GCC should not diagnose potential integer overflow in unreachable
expressions, as that is a common idiom in code that is working correctly.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/49705] -Wstrict-overflow should not diagnose unevaluated expressions
2011-07-11 18:18 [Bug c/49705] New: -Wstrict-overflow should not diagnose unevaluated expressions eggert at gnu dot org
@ 2011-07-12 8:57 ` rguenth at gcc dot gnu.org
2011-07-12 14:25 ` ian at airs dot com
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-07-12 8:57 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49705
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Keywords| |diagnostic
Last reconfirmed| |2011.07.12 08:57:17
Component|c |middle-end
CC| |iant at google dot com
Ever Confirmed|0 |1
--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-07-12 08:57:17 UTC ---
Confirmed. And very difficult to fix.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/49705] -Wstrict-overflow should not diagnose unevaluated expressions
2011-07-11 18:18 [Bug c/49705] New: -Wstrict-overflow should not diagnose unevaluated expressions eggert at gnu dot org
2011-07-12 8:57 ` [Bug middle-end/49705] " rguenth at gcc dot gnu.org
@ 2011-07-12 14:25 ` ian at airs dot com
2011-07-12 14:26 ` ian at airs dot com
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: ian at airs dot com @ 2011-07-12 14:25 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49705
Ian Lance Taylor <ian at airs dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ian at airs dot com
--- Comment #2 from Ian Lance Taylor <ian at airs dot com> 2011-07-12 14:25:13 UTC ---
Very difficult to fix in the general case but easy to fix in this particular
case. When the warning is issued, c_inhibit_evaluation_warnings is 1. All we
need to do is, when setting c_inhibit_evaluation_warnings non-zero, also call
fold_defer_overflow_warnings.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/49705] -Wstrict-overflow should not diagnose unevaluated expressions
2011-07-11 18:18 [Bug c/49705] New: -Wstrict-overflow should not diagnose unevaluated expressions eggert at gnu dot org
2011-07-12 8:57 ` [Bug middle-end/49705] " rguenth at gcc dot gnu.org
2011-07-12 14:25 ` ian at airs dot com
@ 2011-07-12 14:26 ` ian at airs dot com
2011-07-12 16:34 ` eggert at gnu dot org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: ian at airs dot com @ 2011-07-12 14:26 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49705
--- Comment #3 from Ian Lance Taylor <ian at airs dot com> 2011-07-12 14:25:56 UTC ---
Created attachment 24744
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24744
Possible patch
Here is a possible patch to fix this test case.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/49705] -Wstrict-overflow should not diagnose unevaluated expressions
2011-07-11 18:18 [Bug c/49705] New: -Wstrict-overflow should not diagnose unevaluated expressions eggert at gnu dot org
` (2 preceding siblings ...)
2011-07-12 14:26 ` ian at airs dot com
@ 2011-07-12 16:34 ` eggert at gnu dot org
2011-07-12 16:43 ` ian at airs dot com
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: eggert at gnu dot org @ 2011-07-12 16:34 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49705
--- Comment #4 from eggert at gnu dot org 2011-07-12 16:30:44 UTC ---
Created attachment 24747
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24747
longer, more-realistic test case
Thanks for looking into the problem. If it helps, attached is a longer test
case that more-closely corresponds to the original problem that I had
with the Emacs source code.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/49705] -Wstrict-overflow should not diagnose unevaluated expressions
2011-07-11 18:18 [Bug c/49705] New: -Wstrict-overflow should not diagnose unevaluated expressions eggert at gnu dot org
` (3 preceding siblings ...)
2011-07-12 16:34 ` eggert at gnu dot org
@ 2011-07-12 16:43 ` ian at airs dot com
2011-07-12 22:48 ` ian at airs dot com
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: ian at airs dot com @ 2011-07-12 16:43 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49705
--- Comment #5 from Ian Lance Taylor <ian at airs dot com> 2011-07-12 16:42:07 UTC ---
My proposed patch also fixes the larger test case. Without the patch I see
this:
strict-overflow-bug.c: In function ‘check_image_width’:
strict-overflow-bug.c:14:4: warning: assuming signed overflow does not occur
when assuming that (X + c) >= X is always true [-Wstrict-overflow]
With the patch I see no warning. This is compiling with -O2 -Wstrict-overflow.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/49705] -Wstrict-overflow should not diagnose unevaluated expressions
2011-07-11 18:18 [Bug c/49705] New: -Wstrict-overflow should not diagnose unevaluated expressions eggert at gnu dot org
` (4 preceding siblings ...)
2011-07-12 16:43 ` ian at airs dot com
@ 2011-07-12 22:48 ` ian at airs dot com
2011-07-21 21:31 ` ian at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: ian at airs dot com @ 2011-07-12 22:48 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49705
Ian Lance Taylor <ian at airs dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
AssignedTo|unassigned at gcc dot |ian at airs dot com
|gnu.org |
--- Comment #6 from Ian Lance Taylor <ian at airs dot com> 2011-07-12 22:47:33 UTC ---
Patch tested and sent for approval.
http://gcc.gnu.org/ml/gcc-patches/2011-07/msg00971.html
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/49705] -Wstrict-overflow should not diagnose unevaluated expressions
2011-07-11 18:18 [Bug c/49705] New: -Wstrict-overflow should not diagnose unevaluated expressions eggert at gnu dot org
` (5 preceding siblings ...)
2011-07-12 22:48 ` ian at airs dot com
@ 2011-07-21 21:31 ` ian at gcc dot gnu.org
2011-07-21 21:32 ` ian at airs dot com
2011-09-21 15:47 ` manu at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: ian at gcc dot gnu.org @ 2011-07-21 21:31 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49705
--- Comment #7 from ian at gcc dot gnu.org <ian at gcc dot gnu.org> 2011-07-21 21:30:26 UTC ---
Author: ian
Date: Thu Jul 21 21:30:24 2011
New Revision: 176591
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=176591
Log:
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.
Added:
trunk/gcc/testsuite/gcc.dg/pr49705.c
Modified:
trunk/gcc/c-family/ChangeLog
trunk/gcc/c-family/c-common.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/49705] -Wstrict-overflow should not diagnose unevaluated expressions
2011-07-11 18:18 [Bug c/49705] New: -Wstrict-overflow should not diagnose unevaluated expressions eggert at gnu dot org
` (6 preceding siblings ...)
2011-07-21 21:31 ` ian at gcc dot gnu.org
@ 2011-07-21 21:32 ` ian at airs dot com
2011-09-21 15:47 ` manu at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: ian at airs dot com @ 2011-07-21 21:32 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49705
Ian Lance Taylor <ian at airs dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |NEW
--- Comment #8 from Ian Lance Taylor <ian at airs dot com> 2011-07-21 21:32:01 UTC ---
Fixed in mainline.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug middle-end/49705] -Wstrict-overflow should not diagnose unevaluated expressions
2011-07-11 18:18 [Bug c/49705] New: -Wstrict-overflow should not diagnose unevaluated expressions eggert at gnu dot org
` (7 preceding siblings ...)
2011-07-21 21:32 ` ian at airs dot com
@ 2011-09-21 15:47 ` manu at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: manu at gcc dot gnu.org @ 2011-09-21 15:47 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49705
Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |manu at gcc dot gnu.org
Resolution| |FIXED
--- Comment #9 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2011-09-21 15:33:24 UTC ---
(In reply to comment #8)
> Fixed in mainline.
So closing.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2011-09-21 15:33 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-11 18:18 [Bug c/49705] New: -Wstrict-overflow should not diagnose unevaluated expressions eggert at gnu dot org
2011-07-12 8:57 ` [Bug middle-end/49705] " rguenth at gcc dot gnu.org
2011-07-12 14:25 ` ian at airs dot com
2011-07-12 14:26 ` ian at airs dot com
2011-07-12 16:34 ` eggert at gnu dot org
2011-07-12 16:43 ` ian at airs dot com
2011-07-12 22:48 ` ian at airs dot com
2011-07-21 21:31 ` ian at gcc dot gnu.org
2011-07-21 21:32 ` ian at airs dot com
2011-09-21 15:47 ` manu at gcc dot gnu.org
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).