From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4910 invoked by alias); 27 Sep 2016 14:42:52 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 4899 invoked by uid 89); 27 Sep 2016 14:42:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM autolearn=no version=3.3.2 spammy= X-HELO: mail-oi0-f44.google.com Received: from mail-oi0-f44.google.com (HELO mail-oi0-f44.google.com) (209.85.218.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 27 Sep 2016 14:42:41 +0000 Received: by mail-oi0-f44.google.com with SMTP id a62so17577449oib.1 for ; Tue, 27 Sep 2016 07:42:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=KlOqPAt1krPzUuIZ8mfAmbHNQdRP81Mpv9P3ufLfsXg=; b=YjilG1fLWEBO18APNN55aiBKyD/W8MzxSTvdheh7a/SR+U+cyEj+4l+kgd46ENuOvh jZj1e56mCwvDSc/450ZPzPA+5ISc9YANf/+GtN1+V3t18i3g8Xt4BgYC2tsh3MHBL63g gaGccDm+UGfUc7K4ExwgOcG9I8AtRsoapxHA2AZRZKVUmsREJWlwsMcPx/cyjHek2LKX 8MEl9l8nlzdO9cjFfNzwPQ93JE6UKxw6PnNsHUf9iau2KJIY7o7Iw4AZAkDN/yyrc5ls TWU+jXmw3jzvsq3liJ+V0AveqzkdfGoLIQcfJRneLEtqbHhcqVcJ6M0oKUGlCpjfkbvH TG2Q== X-Gm-Message-State: AE9vXwO73EA4gPuD/Yr/HYxyQeDMhyQQIISUhG8fIoAIwheDNw6vHx4yyoMqdZlcP2sy0i7jpHLV546Tj5uZASRO X-Received: by 10.202.83.70 with SMTP id h67mr30991651oib.87.1474987359938; Tue, 27 Sep 2016 07:42:39 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.105.167 with HTTP; Tue, 27 Sep 2016 07:42:19 -0700 (PDT) In-Reply-To: References: <87shslv769.fsf@mid.deneb.enyo.de> <87fuol77ri.fsf@mid.deneb.enyo.de> From: Jason Merrill Date: Tue, 27 Sep 2016 14:51:00 -0000 Message-ID: Subject: Re: [PATCH] Make -Wint-in-bool-context warn on suspicious shift ops To: Bernd Edlinger Cc: Florian Weimer , "gcc-patches@gcc.gnu.org" , Jeff Law Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2016-09/txt/msg02002.txt.bz2 On Tue, Sep 27, 2016 at 10:28 AM, Bernd Edlinger wrote: > On 09/27/16 16:10, Florian Weimer wrote: >> * Bernd Edlinger: >> >>>> =E2=80=9C0 << 0=E2=80=9D is used in a similar context, to create a zer= o constant for a >>>> multi-bit subfield of an integer. >>>> >>>> This example comes from GDB, in bfd/elf64-alpha.c: >>>> >>>> | insn =3D INSN_ADDQ | (16 << 21) | (0 << 16) | (0 << 0); >>>> >>> >>> Of course that is not a boolean context, and will not get a warning. >>> >>> Question is if "if (1 << 0)" is possibly a miss-spelled "if (1 < 0)". >>> >>> Maybe 1 and 0 come from macro expansion.... >> >> But what's the intent of treating 1 << 0 and 0 << 0 differently in the >> patch, then? > > I am not sure if it was a good idea. > > I saw, we had code of the form > bool flag =3D 1 << 2; > > another value LOOKUP_PROTECT is 1 << 0, and > bool flag =3D 1 << 0; > > would at least not overflow the allowed value range of a boolean. Assigning a bit mask to a bool variable is still probably not what was intended, even if it doesn't change the value. Jason