Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2208790iof; Tue, 7 Jun 2022 23:15:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzu+kGsULbOTKQ6UmqRf6WKbIHhzdbj2Tok5Rx6BDuYDgdFR2xphOzUwD0dyUSLkdF+qi1W X-Received: by 2002:a17:903:120b:b0:168:98a9:221f with SMTP id l11-20020a170903120b00b0016898a9221fmr844928plh.48.1654668936661; Tue, 07 Jun 2022 23:15:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654668936; cv=none; d=google.com; s=arc-20160816; b=ouT5yB0Gu+/r3QJrVpPCiH5tsh0eJ2lp9eVs9a/3A1KgSjudOCCzkmt/QNkPQ23hxA dEEtpjWDysQfF9heIxZfHUV2IyfJydmhSpD1BSHmuaLTVp94sFrwkXDjLnRqNy0e4c/l t5FYEcbkwBZbPwRFf+pxR+NPMHd4GNkFjPlz77imW1wOKfCGV9Qb6ljuBrtPrdGfwCvS fnP0/iX/4/zMu3/GgytpNS/Hvvqg/4v3y0FJfZ/93Ciy2F1F+AZUJCiLrCzMFVl8NGou Z6p3SBlyTZvQaZ9uy5CR6qMtrDpNXoWO+KxoubxNOaiBUkde06LS91zm3u3BMsrhBtXg 4D1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Xt01xp86lqL0/6AjJBope1HTOp03keAnvABg9sLTIEA=; b=QTqHXeFfR2yqHpP/SOhHT42bJ4TzUqMph2DiYVgAHiabXbYxbwGCs3JwF8cfVSgsf5 kEUAkAHOfR2ObvJRog/c5TiUGB/o3ejthb+rYyc59MkOhlWZ4/co7tdUER3aT2WAj7lv DKJp0R8oNJ/rxs5V0JORCATMjIiyTPBNs7A4TNB3CNuXEbo9goYQBfMMiA8X6JXJKU4i 83vwZ6yiDheszJBRTVTk9gj2pHZP4XFbWjwbgN0673SZAV6Ep0mpcJz7HvESygiy4fF3 qdV11KqvZ1joQ3S6kmUkzZCoPPVrTAwUL6dYZBQJQ55SpcqyeXyRrg4Kz0ZeyanjkoRk DIag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=UHgsazWQ; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id c33-20020a634e21000000b003c6184913b4si26644276pgb.5.2022.06.07.23.15.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 23:15:36 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=UHgsazWQ; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8F17B2D3B26; Tue, 7 Jun 2022 22:37:15 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230077AbiFHByi (ORCPT + 99 others); Tue, 7 Jun 2022 21:54:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1586687AbiFGXvu (ORCPT ); Tue, 7 Jun 2022 19:51:50 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78AA228DC2D for ; Tue, 7 Jun 2022 15:43:10 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id b12so9817041ljq.3 for ; Tue, 07 Jun 2022 15:43:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Xt01xp86lqL0/6AjJBope1HTOp03keAnvABg9sLTIEA=; b=UHgsazWQmeU1NR6jOOBK0qGzfYbJQXzgSI0eKTHcQO2WAP2crTBr7b/+hBIGmTkWET eaeI8PxMo/qMYOJQXvc79Tax4fvqB0zsF+dnhvp4wvLkdHT+KEcQKEYIfyO6dFWS9JAk xRe7n/80iXhEW4gCXmy1KpD6JnslfRdVAmFamIl+GjL5w9+W5S5MLB4lQcEzMogc0Sfh XF4cvnKjdp6lsHLn/Ker4XPQosO2YPJrCGThRBO0DzyMVpLbyoF0wXM1YwginkQVcP8F /ZZtlzXQ6YTWAFzzAeIAaFQH3KIVYsMJh1sMGwJ4CQuqeG6GQ6F82L83ujInHYVddxlK ASIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Xt01xp86lqL0/6AjJBope1HTOp03keAnvABg9sLTIEA=; b=rAlajgo9yYsvY+YbeM1h2VwNEpoiLuZL/7D5IPDAli7kZ3SV4eq4VQt4NdsJuVPDqN enQqyuwyeegt9tVyDCiiXy3VLTNNRbhccefrj59zfviSvgbM76QFoQvOD4sOn7/ixVe9 pibL1PulNQTwIBaa26aCyrmQugquYQvljIyFVQy3fkRpUnbnOnB7EbE4ED8/dxWDVrSP wPwCjKRfhEF7gs7BUa3ullDpZ8ASZiX46l6HpegM1BKcJbmhmj7fe74b0Zh7IjJOu+cH tO7YJRFMcW1cnwpULimH2yNCbEAdHdIvfPafq2sw7LlE4eheEo1HMHsjRYZpzLehvnP9 Pjrw== X-Gm-Message-State: AOAM530kAKqJuyoZY2+Todwyyu/S4JYDrrfX3EWC0SCr0Vy6mTYbd7zG KKXfpLUPWwWE3G2uTPhGGSXlJVQ0h8ql7H+Bv07pMA== X-Received: by 2002:a2e:8e98:0:b0:255:9d3d:bac3 with SMTP id z24-20020a2e8e98000000b002559d3dbac3mr6176311ljk.103.1654641788193; Tue, 07 Jun 2022 15:43:08 -0700 (PDT) MIME-Version: 1.0 References: <20220607222006.22719-1-jstitt007@gmail.com> <20220607152744.d7c801d092529309500ac9a6@linux-foundation.org> In-Reply-To: <20220607152744.d7c801d092529309500ac9a6@linux-foundation.org> From: Nick Desaulniers Date: Tue, 7 Jun 2022 15:42:56 -0700 Message-ID: Subject: Re: [PATCH] include/uapi/linux/swab.h: add __u16 cast to __swab16 conditional To: Andrew Morton Cc: Justin Stitt , Nathan Chancellor , Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Richard Smith Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 On Tue, Jun 7, 2022 at 3:27 PM Andrew Morton wrote: > > On Tue, 7 Jun 2022 15:20:06 -0700 Justin Stitt wrote: > > > if __HAVE_BUILTIN_BSWAP16__ is defined then __swab16 utilizes a __u16 cast. > > This same cast should be used if __HAVE_BUILTIN_BSWAP16__ is not defined as > > well. This should fix loads (at least a few) clang -Wformat warnings > > specifically with `ntohs()` > > > > ... > > > > --- a/include/uapi/linux/swab.h > > +++ b/include/uapi/linux/swab.h > > @@ -102,7 +102,7 @@ static inline __attribute_const__ __u32 __fswahb32(__u32 val) > > #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x)) > > #else > > #define __swab16(x) \ > > - (__builtin_constant_p((__u16)(x)) ? \ > > + (__u16)(__builtin_constant_p((__u16)(x)) ? \ > > ___constant_swab16(x) : \ > > __fswab16(x)) > > #endif > > More explanation, please? Both ___constant_swab16() and __fswab16() > return __u16, so why does this patch have any effect? > See this example: https://godbolt.org/z/fzE73jn13 And the ImplicitCastExpr nodes adding to the AST: https://godbolt.org/z/oYeYxYdKW Both the second and third operand are promoted to int. C11: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf 6.5.15/5 >> If both the second and third operands have arithmetic type, the result type that would be determined by the usual arithmetic conversions, were they applied to those two operands, is the type of the result. 6.3.1.8/1 >> Otherwise, the integer promotions are performed on both operands. 6.3.1.1/2 >> If an int can represent all values of the original type (as restricted by the width, for a bit-field), the value is converted to an int; otherwise, it is converted to an unsigned int. These are called the integer promotions. -- Thanks, ~Nick Desaulniers