Bug 17534 - gcc fails to diagnose suspect expressions that have incompatible bit masks
Summary: gcc fails to diagnose suspect expressions that have incompatible bit masks
Status: RESOLVED DUPLICATE of bug 66555
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.0.0
: P2 enhancement
Target Milestone: 6.0
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
: 46582 59491 65423 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-09-17 14:53 UTC by Tom Truscott
Modified: 2023-05-20 04:14 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 10.1.0, 11.1.0, 8.1.0
Known to fail: 6.1.0, 7.1.0
Last reconfirmed: 2006-02-13 04:10:57


Attachments
proposed patch (1.26 KB, patch)
2004-09-20 20:40 UTC, Tom Truscott
Details | Diff
revised patch (1.14 KB, patch)
2004-10-05 16:10 UTC, Tom Truscott
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Truscott 2004-09-17 14:53:07 UTC
The expressions (z & 2) == 4 and (z | 2) == 4 are always false. When these
appear in programs it is almost always unintended, but gcc fails to warn the user.

An example undiagnosed mistake appears in gcc/gcc/java/parse.y near line 1154
                  /* Can't have a static initializer in an innerclass */
                  if ($1 | ACC_STATIC &&
                      ...
The '|' is unlikely to have been intended.

I added a warning for this to "my" gcc years ago, and it works well.  I recently
got this warning added to the Java "findbugs" tool
http://findbugs.sourceforge.net/bugDescriptions.html (That took less than a
week, in stark contrast to my experiences with gcc).

I have a patch, but this web form lacks a way to supply it.
Comment 1 Tom Truscott 2004-09-20 20:40:45 UTC
Created attachment 7179 [details]
proposed patch
Comment 2 Andrew Pinski 2004-09-20 20:50:45 UTC
Hmm, I think I thought I saw this somewhere else.

Confirmed.
Comment 3 Tom Truscott 2004-09-29 16:10:25 UTC
Re: "think I thought I saw this somewhere else".
This patch includes a fix for previously reported PR 16632. That has gone
nowhere so I decided to report the enhancement that I actually want.
Comment 4 Tom Truscott 2004-10-05 16:10:47 UTC
Created attachment 7285 [details]
revised patch

The fix for PR 16632 invalidates the previously proposed patch.  Here is new
one.
Comment 5 Tom Truscott 2005-11-15 15:43:39 UTC
Since fold() is increasingly used for internal speculative computations, I think it should avoid issuing warnings as false positives are too likely.  So perhaps this warning belongs in parser_build_binary_op() in c-typeck.c

Similarly for bug 16302
Comment 6 Manuel López-Ibáñez 2011-10-21 14:10:52 UTC
Still an issue with revision 180166. This could be warned by Wlogical-op.
Comment 7 Marek Polacek 2015-03-16 15:46:15 UTC
*** Bug 59491 has been marked as a duplicate of this bug. ***
Comment 8 Marek Polacek 2015-03-16 15:46:58 UTC
*** Bug 65423 has been marked as a duplicate of this bug. ***
Comment 9 Manuel López-Ibáñez 2015-03-19 16:11:34 UTC
*** Bug 46582 has been marked as a duplicate of this bug. ***
Comment 10 Andrew Pinski 2023-05-20 04:14:45 UTC
Fixed for GCC 6 by r6-2453-g05b28fd6f91016 (aka PR 66555) so just marking as a dup of that bug.

*** This bug has been marked as a duplicate of bug 66555 ***