From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.efficios.com (mail.efficios.com [167.114.26.124]) by sourceware.org (Postfix) with ESMTPS id E070C385842E for ; Mon, 17 Jan 2022 10:50:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E070C385842E Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 378C32F7282; Mon, 17 Jan 2022 05:50:47 -0500 (EST) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id YARegIn4WJH1; Mon, 17 Jan 2022 05:50:46 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id B40D02F7281; Mon, 17 Jan 2022 05:50:46 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com B40D02F7281 X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id UpbObrdVEIIr; Mon, 17 Jan 2022 05:50:46 -0500 (EST) Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) by mail.efficios.com (Postfix) with ESMTPSA id A073E2F6FC8; Mon, 17 Jan 2022 05:50:46 -0500 (EST) Message-ID: <6416247f-d88f-48db-4352-e04988ecfe94@efficios.com> Date: Mon, 17 Jan 2022 05:50:46 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH] bfd/elf64-ppc.c: fix clang -Wbitwise-instead-of-logical warning in ppc64_elf_check_init_fini Content-Language: en-US To: Alan Modra Cc: binutils@sourceware.org References: <20220116031307.17074-1-simon.marchi@efficios.com> From: Simon Marchi In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Jan 2022 10:50:49 -0000 On 2022-01-16 18:10, Alan Modra wrote: > On Sat, Jan 15, 2022 at 10:13:07PM -0500, Simon Marchi via Binutils wrote: >> --- a/bfd/elf64-ppc.c >> +++ b/bfd/elf64-ppc.c >> @@ -13129,7 +13129,7 @@ bool >> ppc64_elf_check_init_fini (struct bfd_link_info *info) >> { >> return (check_pasted_section (info, ".init") >> - & check_pasted_section (info, ".fini")); >> + && check_pasted_section (info, ".fini")); >> } >> >> /* See whether we can group stub sections together. Grouping stub > > I think I'd rather see this fixed by > > bool ret1 = check_pasted_section (info, ".init"); > bool ret2 = check_pasted_section (info, ".fini"); > return ret1 && ret1; > > check_pasted_section has a side effect, and failure normally only > produces a warning. > No problem, here's the updated patch. >From bb27b41b2cd0dc4ebbbc8de6cfc5b691281695f1 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Sat, 15 Jan 2022 22:13:07 -0500 Subject: [PATCH] bfd/elf64-ppc.c: fix clang -Wbitwise-instead-of-logical warning in ppc64_elf_check_init_fini I see this error with clang-14: CC elf64-ppc.lo /home/smarchi/src/binutils-gdb/bfd/elf64-ppc.c:13131:11: error: use of bitwise '&' with boolean operands [-Werror,-Wbitwise-instead-of-logical] return (check_pasted_section (info, ".init") ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Fix by replacing & with &&. But given that the check_pasted_section function has side-effects and we want to make sure both calls are made, assign to temporary variables before evaluating the `&&`. Change-Id: I849e1b2401bea5f4d8ef3ab9af99ba9e3ef42490 --- bfd/elf64-ppc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c index ea9e60217bc3..206d85b319da 100644 --- a/bfd/elf64-ppc.c +++ b/bfd/elf64-ppc.c @@ -13128,8 +13128,10 @@ check_pasted_section (struct bfd_link_info *info, const char *name) bool ppc64_elf_check_init_fini (struct bfd_link_info *info) { - return (check_pasted_section (info, ".init") - & check_pasted_section (info, ".fini")); + bool ret1 = check_pasted_section (info, ".init"); + bool ret2 = check_pasted_section (info, ".fini"); + + return ret1 && ret2; } /* See whether we can group stub sections together. Grouping stub base-commit: ab31da6aff52fe3206cba98c03d7f74159da8677 -- 2.34.1