Summary: | -Wstrict-overflow should not diagnose unevaluated expressions | ||
---|---|---|---|
Product: | gcc | Reporter: | Paul Eggert <eggert> |
Component: | middle-end | Assignee: | Ian Lance Taylor <ian> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | ian, iant, manu |
Priority: | P3 | Keywords: | diagnostic |
Version: | 4.6.1 | ||
Target Milestone: | --- | ||
Host: | x86_64-unknown-linux-gnu | Target: | x86_64-unknown-linux-gnu |
Build: | x86_64-unknown-linux-gnu | Known to work: | |
Known to fail: | Last reconfirmed: | 2011-07-12 08:57:17 | |
Attachments: |
Possible patch
longer, more-realistic test case |
Description
Paul Eggert
2011-07-11 18:17:58 UTC
Confirmed. And very difficult to fix. 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. Created attachment 24744 [details]
Possible patch
Here is a possible patch to fix this test case.
Created attachment 24747 [details]
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.
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. Patch tested and sent for approval. http://gcc.gnu.org/ml/gcc-patches/2011-07/msg00971.html 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 Fixed in mainline. (In reply to comment #8) > Fixed in mainline. So closing. |