From patchwork Mon Jan 23 18:48:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Karcher X-Patchwork-Id: 47331 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1765550wrn; Mon, 23 Jan 2023 10:55:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXthVENLhJcJDnGfDvPRmwVn0SufRWesrxE/oMj0Z1ZSsh8D8V8szXa1CmDwADbXIafqLoZq X-Received: by 2002:a17:907:214c:b0:838:1b80:9a7a with SMTP id rk12-20020a170907214c00b008381b809a7amr27136784ejb.12.1674500129466; Mon, 23 Jan 2023 10:55:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674500129; cv=none; d=google.com; s=arc-20160816; b=qI6KP4c/TNV8wbWw4gXjkyvgcGCBigw7gSRtL8izT5T6Eaob0QLIVgvqzx6v0W/hQG ZFZMdzRF4y7eFRQO78Csu+OxJ1auj1IdvA6jX0hD7LnRcsqHNKAMobkHt63NjOaRg8U0 e+w0IufOvabr6ESOM6/Slzkoe8M4IlMERRxP/isYR6xN1Vz2+Jfv1D5+UWqZG5tCgLpt PVhRQ1oK6PdRg6GIBbIf2kAkRHUivVvRhImGmYNKPaNTdrqpZtaW8ehK3BfNFRrPts45 sGQDJReC6ul1iXtQkE2sa68glTjr/ZRmk2shQOCNafKimWNEKBQ5Gv07mncON2Sr9PUi 4mVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:to:subject:from :user-agent:mime-version:date:message-id; bh=gluG0ZF9F5FWTG9G9hUnb7h82JATpTNoaJk8aE90cd4=; b=wSIJdEtJBkPjigigMbEgMlseIBaMEQqUbeB3Xhwy5NKOkn+TYeAvqBcJYywof0FbbR 2pbts7Kr3S7UVjdBK2L7TiUIAf20dvy3/0eHH30LT9y5lkaKtqDWTPvm2L7oOVndpoXz bCl5AD/KX5Aj2+hsplzWR2OuzNd4rBo68gNnuomBcQHIPbvjae01kRX9WITRz/Gt0y3m 50flU3vHH22pt2GlsWNRgUnO+gorb0n5k9mP/tdob5A+GC3MA9w3oYc42aXKZaYpqY0T FQAuj5l55UE6Sx71CpWPPnaQV8NSC2kLBmYm9669GITicZFeI/gNJFS4FghLubcB8jHL MC5Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u18-20020a056402065200b0049df78b34efsi177819edx.57.2023.01.23.10.55.06; Mon, 23 Jan 2023 10:55:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231490AbjAWStI (ORCPT + 99 others); Mon, 23 Jan 2023 13:49:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232336AbjAWStD (ORCPT ); Mon, 23 Jan 2023 13:49:03 -0500 Received: from outpost1.zedat.fu-berlin.de (outpost1.zedat.fu-berlin.de [130.133.4.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28D0C10A90; Mon, 23 Jan 2023 10:49:01 -0800 (PST) Received: from inpost2.zedat.fu-berlin.de ([130.133.4.69]) by outpost.zedat.fu-berlin.de (Exim 4.95) with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (envelope-from ) id 1pK1sJ-003mag-PP; Mon, 23 Jan 2023 19:48:59 +0100 Received: from pd9f631ca.dip0.t-ipconnect.de ([217.246.49.202] helo=[192.168.144.87]) by inpost2.zedat.fu-berlin.de (Exim 4.95) with esmtpsa (TLS1.3) tls TLS_AES_128_GCM_SHA256 (envelope-from ) id 1pK1sJ-00024b-JI; Mon, 23 Jan 2023 19:48:59 +0100 Message-ID: Date: Mon, 23 Jan 2023 19:48:58 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 From: Michael Karcher Subject: [PATCH v4 1/1] arch/sh: avoid spurious sizeof-pointer-div warning To: linux-kernel@vger.kernel.org, linux-sh@vger.kernel.org, Segher Boessenkool , Rich Felker , Yoshinori Sato , John Paul Adrian Glaubitz X-Original-Sender: kernel@mkarcher.dialup.fu-berlin.de X-Originating-IP: 217.246.49.202 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755840623230002463?= X-GMAIL-MSGID: =?utf-8?q?1755840647614590256?= Gcc warns about the pattern sizeof(void*)/sizeof(void), as it looks like the abuse of a pattern to calculate the array size. This pattern appears in the unevaluated part of the ternary operator in _INTC_ARRAY if the parameter is NULL. The replacement uses an alternate approach to return 0 in case of NULL which does not generate the pattern sizeof(void*)/sizeof(void), but still emits the warning if _INTC_ARRAY is called with a nonarray parameter. This patch is required for successful compilation with -Werror enabled. The idea to use _Generic for type distinction is taken from Comment #7 in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108483 by Jakub Jelinek Signed-off-by: Michael Karcher Acked-by: Randy Dunlap # build-tested Reviewed-by: Geert Uytterhoeven Tested-by: Geert Uytterhoeven --- This edition of the mail has the correct "v4" designation in the subject. History: v4: - Put the case distinction into the numerator instead of the denominator - Refactor the case disctinction into a second macro v3: - I had a stern discussion with Thunderbird about not mangling the space characters in my email, and I hope spaces get sent as standard spaces now v2: - improve title and remove mostly redundant first sentence of the description - adjust formatting of the _Generic construction diff --git a/include/linux/sh_intc.h b/include/linux/sh_intc.h index c255273b0281..98d1da0d8e36 100644 --- a/include/linux/sh_intc.h +++ b/include/linux/sh_intc.h @@ -97,7 +97,9 @@ struct intc_hw_desc { unsigned int nr_subgroups; }; -#define _INTC_ARRAY(a) a, __same_type(a, NULL) ? 0 : sizeof(a)/sizeof(*a) +#define _INTC_SIZEOF_OR_ZERO(a) (_Generic(a, \ + typeof(NULL): 0, \ + default: sizeof(a))) +#define _INTC_ARRAY(a) a, _INTC_SIZEOF_OR_ZERO(a)/sizeof(*a) #define INTC_HW_DESC(vectors, groups, mask_regs, \ prio_regs, sense_regs, ack_regs) \