From patchwork Mon Apr 16 11:11:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 898580 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-476423-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="CqM+JY0x"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40PmXc3Nhcz9s1l for ; Mon, 16 Apr 2018 21:35:43 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=iMhYIINWp6RA1UeaW mvJ0yDdJoor+9IUlrU7gopFcmjn0FbHeTmo324k5cbW1FKVwAnk8Z7KFfdlozp2F WVXuHxF4qIpDbc90CTY5layylHizstqGU1ZAVHwJMvE/n3li7ER7B5Vnf+8SgNuj MZgOruJbqSY+KGLpJEFbtkVr3E= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; s=default; bh=9jprYfJa2ngo3lnosbqqNKS wh7E=; b=CqM+JY0xtl8psEMQXjGJG8xbTIQct29RcNmoELkVUhd4s1wP0+YBMKg N6rDBm7SrXlQ+uGRGO3MKVZf7ujs0BM1yyTNt76YH4Crt/kjyDGYBwyisZ1T9xdp r2Mc42gCXfM3zkUYBl0K+emTd+6PTpmp74iOP+E1LL8bN2P50CE4= Received: (qmail 104712 invoked by alias); 16 Apr 2018 11:35:35 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 104694 invoked by uid 89); 16 Apr 2018 11:35:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 16 Apr 2018 11:35:34 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0D39DEC012 for ; Mon, 16 Apr 2018 11:35:29 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.36.118.110]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0DDE12026DFD for ; Mon, 16 Apr 2018 11:35:27 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id w3GBBZ0h019653; Mon, 16 Apr 2018 13:11:35 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w3GBBW8F019652; Mon, 16 Apr 2018 13:11:32 +0200 Date: Mon, 16 Apr 2018 13:11:32 +0200 From: Jakub Jelinek To: Uros Bizjak , Kirill Yukhin , Thomas Schwinge Cc: gcc-patches@gcc.gnu.org, hjl.tools@gmail.com, "Koval, Julia" Subject: [PATCH] Fix libgcc/config/i386/cpuinfo.c warnings (PR target/84945) Message-ID: <20180416111132.GP8577@tucnak> Reply-To: Jakub Jelinek References: <20180319193556.GO8577@tucnak> <87lgdns9vu.fsf@euler.schwinge.homeip.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <87lgdns9vu.fsf@euler.schwinge.homeip.net> User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes On Mon, Apr 16, 2018 at 12:50:29PM +0200, Thomas Schwinge wrote: > > +#define set_feature(f) \ > > + if (f < 32) features |= (1U << f); else features2 |= (1U << (f - 32)) > > if (edx & bit_CMOV) > > - features |= (1 << FEATURE_CMOV); > > + set_feature (FEATURE_CMOV); > > [...]/libgcc/config/i386/cpuinfo.c: In function 'get_available_features': > [...]/libgcc/config/i386/cpuinfo.c:278:60: warning: left shift count is negative [-Wshift-count-negative] > if (f < 32) features |= (1U << f); else features2 |= (1U << (f - 32)) > ^~ > [...]/libgcc/config/i386/cpuinfo.c:281:5: note: in expansion of macro 'set_feature' > set_feature (FEATURE_CMOV); > ^~~~~~~~~~~ > [...]/libgcc/config/i386/cpuinfo.c:280:6: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else] > if (edx & bit_CMOV) > ^ > [Many more.] Oops, missed these. All of the warnings are false positives (warn on dead code) or style warning (-Wdangling-else), not actual code bugs. The following patch fixes all the warnings without changing code generation, we are using set_feature with constant arguments only, so everything is folded properly anyway. Ok for trunk? 2018-04-16 Jakub Jelinek PR target/84945 * config/i386/cpuinfo.c (set_feature): Wrap into do while (0) to avoid -Wdangling-else warnings. Mask shift counts to avoid -Wshift-count-negative and -Wshift-count-overflow false positives. Jakub --- libgcc/config/i386/cpuinfo.c.jj 2018-03-30 20:37:37.683185248 +0200 +++ libgcc/config/i386/cpuinfo.c 2018-04-16 13:04:45.239490344 +0200 @@ -275,7 +275,14 @@ get_available_features (unsigned int ecx } #define set_feature(f) \ - if (f < 32) features |= (1U << f); else features2 |= (1U << (f - 32)) + do \ + { \ + if (f < 32) \ + features |= (1U << (f & 31)); \ + else \ + features2 |= (1U << ((f - 32) & 31)); \ + } \ + while (0) if (edx & bit_CMOV) set_feature (FEATURE_CMOV);