From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 613 invoked by alias); 16 Sep 2019 04:33:39 -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 595 invoked by uid 89); 16 Sep 2019 04:33:39 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 spammy=MASK, D*cz, D*suse.cz, newly X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-2.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 16 Sep 2019 04:33:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1568608415; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FJfeOMROmEifs9642Bqvkgr5H2GW8SlNkZEJ3luxICE=; b=MCHGX5FfaOVqF20TxQx6qDjknbZT05zCsrX79fctU34LifWZDoTvWxdwNhLAw0l3RKyKup HNGMAeA4EVw38DYoeDKj9veesnQcQedrstXlTkKbsPoBzAbgcaMz6LjPmq32qQYWMKTJGU n4ntrIWO2vhM2HbjwNPwig1XCn1eQK0= Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-31-0mgA9Vc1MnCliJN6m47LzQ-1; Mon, 16 Sep 2019 00:33:32 -0400 Received: by mail-io1-f72.google.com with SMTP id o6so35242899ioh.10 for ; Sun, 15 Sep 2019 21:33:32 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([72.142.123.242]) by smtp.gmail.com with ESMTPSA id c4sm28992888ioa.76.2019.09.15.21.33.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Sep 2019 21:33:30 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [C++ PATCH 1/4] Handle location wrappers better in warn_logical_operator. Date: Mon, 16 Sep 2019 04:33:00 -0000 Message-Id: <20190916043328.3739-1-jason@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2019-09/txt/msg00924.txt.bz2 When we introduced location wrappers, we added fold_for_warn to warnings that are interested in a constant value, or wrapper-stripping to warnings that are interested in literal constants. This particular warning is looking for a literal constant, but was wrongly changed to use fold_for_warn; this patch makes it strip instead. Tested x86_64-pc-linux-gnu, applying to trunk. * c-warn.c (warn_logical_operator): Strip location wrappers. Don't fold_for_warn in "|| mask" warning. --- gcc/c-family/c-warn.c | 40 ++++++++++++++++++++-------------------- gcc/c-family/ChangeLog | 5 +++++ 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c index d671b77a2b0..bee5449bcb1 100644 --- a/gcc/c-family/c-warn.c +++ b/gcc/c-family/c-warn.c @@ -208,32 +208,32 @@ warn_logical_operator (location_t location, enum tree= _code code, tree type, programmer. That is, an expression such as op && MASK where op should not be any boolean expression, nor a constant, and mask seems to be a non-boolean integer constant. */ + STRIP_ANY_LOCATION_WRAPPER (op_right); if (TREE_CODE (op_right) =3D=3D CONST_DECL) /* An enumerator counts as a constant. */ op_right =3D DECL_INITIAL (op_right); + tree stripped_op_left =3D tree_strip_any_location_wrapper (op_left); if (!truth_value_p (code_left) && INTEGRAL_TYPE_P (TREE_TYPE (op_left)) - && !CONSTANT_CLASS_P (op_left) - && !TREE_NO_WARNING (op_left)) + && !CONSTANT_CLASS_P (stripped_op_left) + && TREE_CODE (stripped_op_left) !=3D CONST_DECL + && !TREE_NO_WARNING (op_left) + && TREE_CODE (op_right) =3D=3D INTEGER_CST + && !integer_zerop (op_right) + && !integer_onep (op_right)) { - tree folded_op_right =3D fold_for_warn (op_right); - if (TREE_CODE (folded_op_right) =3D=3D INTEGER_CST - && !integer_zerop (folded_op_right) - && !integer_onep (folded_op_right)) - { - bool warned; - if (or_op) - warned - =3D warning_at (location, OPT_Wlogical_op, - "logical % applied to non-boolean constant"); - else - warned - =3D warning_at (location, OPT_Wlogical_op, - "logical % applied to non-boolean constant"); - if (warned) - TREE_NO_WARNING (op_left) =3D true; - return; - } + bool warned; + if (or_op) + warned + =3D warning_at (location, OPT_Wlogical_op, + "logical % applied to non-boolean constant"); + else + warned + =3D warning_at (location, OPT_Wlogical_op, + "logical % applied to non-boolean constant"); + if (warned) + TREE_NO_WARNING (op_left) =3D true; + return; } =20 /* We do not warn for constants because they are typical of macro diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 2b700c2c4bd..93bdf3e0798 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +2019-09-15 Jason Merrill + + * c-warn.c (warn_logical_operator): Strip location wrappers. Don't + fold_for_warn in "|| mask" warning. + 2019-09-10 Martin Liska =20 * c.opt: Use newly added WarnRemoved. base-commit: ce026385ee57427978053620a038bffaac90819e --=20 2.21.0