From: Bernd Edlinger <bernd.edlinger@hotmail.de>
To: Joseph Myers <joseph@codesourcery.com>
Cc: Markus Trippelsdorf <markus@trippelsdorf.de>,
Jason Merrill <jason@redhat.com>,
Florian Weimer <fw@deneb.enyo.de>,
"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
Jeff Law <law@redhat.com>
Subject: Re: [PATCH] Make -Wint-in-bool-context warn on suspicious shift ops
Date: Tue, 18 Oct 2016 18:14:00 -0000 [thread overview]
Message-ID: <AM4PR0701MB2162FAB66D1F87E5197975AAE4D30@AM4PR0701MB2162.eurprd07.prod.outlook.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1610181704560.22314@digraph.polyomino.org.uk>
[-- Attachment #1: Type: text/plain, Size: 518 bytes --]
On 10/18/16 19:05, Joseph Myers wrote:
> On Tue, 18 Oct 2016, Bernd Edlinger wrote:
>
>> Hi,
>>
>> this restricts the -Wint-in-bool-context warning to signed shifts,
>> to reduce the number of false positives Markus reported yesterday.
>
> This patch seems to be missing testcases (that warned before the patch
> and don't warn after it).
>
Yes of course.
New patch, this time with a test case, compiled from the linux sample.
Bootstrapped and reg-tested as usual.
Is it OK for trunk?
Bernd.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch-bool-context4.diff --]
[-- Type: text/x-patch; name="patch-bool-context4.diff", Size: 1666 bytes --]
c-family:
2016-10-17 Bernd Edlinger <bernd.edlinger@hotmail.de>
* c-common.c (c_common_truthvalue_conversion): Warn only for signed
integer shift ops in boolean context.
testsuite:
2016-10-17 Bernd Edlinger <bernd.edlinger@hotmail.de>
* c-c++-common/Wint-in-bool-context-2.c: New test.
Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c (revision 241270)
+++ gcc/c-family/c-common.c (working copy)
@@ -3328,8 +3328,10 @@
TREE_OPERAND (expr, 0));
case LSHIFT_EXPR:
- warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
- "<< in boolean context, did you mean '<' ?");
+ if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
+ && !TYPE_UNSIGNED (TREE_TYPE (expr)))
+ warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context,
+ "<< in boolean context, did you mean '<' ?");
break;
case COND_EXPR:
Index: gcc/testsuite/c-c++-common/Wint-in-bool-context-2.c
===================================================================
--- gcc/testsuite/c-c++-common/Wint-in-bool-context-2.c (revision 0)
+++ gcc/testsuite/c-c++-common/Wint-in-bool-context-2.c (working copy)
@@ -0,0 +1,17 @@
+/* { dg-options "-Wint-in-bool-context" } */
+/* { dg-do compile } */
+
+typedef unsigned u32;
+typedef unsigned char u8;
+#define KEYLENGTH 8
+
+int foo (u8 plen, u32 key)
+{
+ if ((plen < KEYLENGTH) && (key << plen)) /* { dg-bogus "boolean context" } */
+ return -1;
+
+ if ((plen << KEYLENGTH) && (key < plen)) /* { dg-warning "boolean context" } */
+ return -2;
+
+ return 0;
+}
next prev parent reply other threads:[~2016-10-18 18:14 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-25 9:14 Bernd Edlinger
2016-09-27 12:45 ` Jason Merrill
2016-09-27 12:58 ` Florian Weimer
2016-09-27 13:56 ` Bernd Edlinger
2016-09-27 14:34 ` Florian Weimer
2016-09-27 14:42 ` Bernd Edlinger
2016-09-27 14:51 ` Jason Merrill
2016-09-27 15:19 ` Bernd Edlinger
2016-09-28 14:44 ` Jason Merrill
2016-09-28 16:17 ` Bernd Edlinger
2016-09-29 18:10 ` Jason Merrill
2016-09-29 19:07 ` Bernd Edlinger
2016-09-29 20:08 ` Bernd Edlinger
2016-09-29 20:53 ` Jason Merrill
2016-09-30 7:05 ` Bernd Edlinger
2016-10-02 18:38 ` Jason Merrill
2016-10-08 17:40 ` Jason Merrill
2016-10-08 20:05 ` Bernd Edlinger
2016-10-09 2:42 ` Jason Merrill
2016-10-17 15:23 ` Markus Trippelsdorf
2016-10-17 16:51 ` Bernd Edlinger
2016-10-17 17:11 ` Markus Trippelsdorf
2016-10-17 17:30 ` Bernd Edlinger
2016-10-17 17:44 ` Markus Trippelsdorf
2016-10-18 17:04 ` Bernd Edlinger
2016-10-18 17:05 ` Joseph Myers
2016-10-18 18:14 ` Bernd Edlinger [this message]
2016-10-19 20:13 ` Jeff Law
2016-10-20 8:05 ` Markus Trippelsdorf
2016-10-20 14:00 ` Bernd Edlinger
2016-09-27 13:48 ` Michael Matz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AM4PR0701MB2162FAB66D1F87E5197975AAE4D30@AM4PR0701MB2162.eurprd07.prod.outlook.com \
--to=bernd.edlinger@hotmail.de \
--cc=fw@deneb.enyo.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=joseph@codesourcery.com \
--cc=law@redhat.com \
--cc=markus@trippelsdorf.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).