From nobody Tue Feb 11 10:10:23 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Yscdl0g26z5nLCj; Tue, 11 Feb 2025 10:10:35 +0000 (UTC) (envelope-from zlei@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Yscdl0W61z3lN2; Tue, 11 Feb 2025 10:10:35 +0000 (UTC) (envelope-from zlei@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1739268635; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=nn8ebaI2XVu6t6Hq+gE7nOo3AJFfdl5GPBX+/DyR4Z8=; b=BO/KW17zOrnrfJdeqAerkCqwJ82YdtaAv7Xh4sug15/hP8B0rHehBlp2DQsbE+5XuQCfIh yBiwCvm1MkgxAniiXcZqDot7qp+KeZUCgpAof9SW5x9+eCK1SKN7YnEbbsEkueKYuP5Gy4 9HxCbLpDNxjOMyIJaxVl/MwppyOYe6qC2q2Nx+/IsT0p3/0hXs0eSu0LlvIm83Ejq9vf7g sgXTI2I07bffkRvVqb7/XzNR0XZuyIZqLRoH5iixl/ju1jhQKWhvwLdsFutlXM6BW5S6Sf 0F+XuWpW5BkuYd4t6PWD7aGK+lfErX7UvI+KS2C75d7S7uaU/IBZJn34LKJYUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1739268635; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=nn8ebaI2XVu6t6Hq+gE7nOo3AJFfdl5GPBX+/DyR4Z8=; b=X7/lwROXx8/g62G1UOaeFs089Zrhqgqnit296Cx03B5IS2tHUPTIk/3kb0EVIIYJyAEpY2 fXYso7ju99/ODc+zDVmzAGdSqpLrGsyivnKemc6TNLb/cQpLprYO/aigMug636ZxHNQmeP otwlnhOBKfL6EOFI9TzYvsg3G3SH2I5pt0ZFKxiUnjobcnAdeWDI0gu7Me7n3ywC4Zm/HS Id/m/YeKML5Oez0bc2PT1qxYEbjnEDdw3faE8BKynubkE7m4vkVaJPB+kfkzI/ci2GlGGe pzZQJAs0XdVLkqkColiMMpB5/9qoieXSHEq1p+9VZbANM6piPrEHsJ8heGvEkA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1739268635; a=rsa-sha256; cv=none; b=Ekrkvo7Oun/iXWCs1OioKc76ZgXF8Whyb24jf4FhhbPBGZaZWFT81wiqS2xBFvFwzXcyVV xQvk/e2ohnVohxPCqsBbBrSymfsNcYYew2TO9Bts7WqNz/W7cRWeBXsjIC8f2Nn8mXKcYD EaTccvL+3w0IIKX34vsncFYx4Vv3EJ6KUOW3ePM7Hz5M9ESAkGsUY4CRur4F0CNleUzXvI pdok6lL1y3/lVb0R5T1fVP6Hl2Cup0KFI5Et0Seg7+Grc5LHCfqo83qZOKJ/imIpEbVqhP K/BnZxGUs+iQhYDucomqWnxQbmt2g/Asrn8TCuOe7w24nzP4y87QOCOm7wbFrA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from smtpclient.apple (unknown [IPv6:2001:19f0:6001:9db:98f0:9fe0:3545:10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: zlei/mail) by smtp.freebsd.org (Postfix) with ESMTPSA id 4Yscdj24sqz1C7R; Tue, 11 Feb 2025 10:10:33 +0000 (UTC) (envelope-from zlei@FreeBSD.org) From: Zhenlei Huang Message-Id: <5BF2F37C-16B4-4B39-B14B-131CE430BB4A@FreeBSD.org> Content-Type: multipart/alternative; boundary="Apple-Mail=_578F92E7-3BA6-4432-8E6C-74615E94D42A" List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.10\)) Subject: Re: git: 7bcc7a0b88cc - stable/14 - libkern: avoid local var in order_base_2() Date: Tue, 11 Feb 2025 18:10:23 +0800 In-Reply-To: <803D3DBC-A4F5-47FB-8034-5241461D4A71@freebsd.org> Cc: Doug Moore , "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-branches@freebsd.org" To: Jessica Clarke References: <202502101115.51ABFISj016298@gitrepo.freebsd.org> <858BD10B-A2C9-4D3A-9FF5-C5573597DF8B@FreeBSD.org> <803D3DBC-A4F5-47FB-8034-5241461D4A71@freebsd.org> X-Mailer: Apple Mail (2.3696.120.41.1.10) --Apple-Mail=_578F92E7-3BA6-4432-8E6C-74615E94D42A Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Feb 11, 2025, at 1:23 PM, Jessica Clarke = wrote: >=20 > On 11 Feb 2025, at 03:30, Zhenlei Huang > wrote: >>> On Feb 10, 2025, at 7:15 PM, Doug Moore wrote: >>>=20 >>> The branch stable/14 has been updated by dougm: >>>=20 >>> URL: = https://cgit.FreeBSD.org/src/commit/?id=3D7bcc7a0b88ccb5e1fe31de88ab9a17e4= 6859318b >>>=20 >>> commit 7bcc7a0b88ccb5e1fe31de88ab9a17e46859318b >>> Author: Doug Moore >>> AuthorDate: 2024-09-27 23:43:07 +0000 >>> Commit: Doug Moore >>> CommitDate: 2025-02-10 10:30:05 +0000 >>>=20 >>> libkern: avoid local var in order_base_2() >>>=20 >>> order_base_2(n) is implemented with a variable, which keeps it from >>> being used at file scope. Implement it instead as ilog2(2*n-1), = which >>> produces a different result when 2*n overflows, which appears = unlikely >>> in practice. >>>=20 >>> Reviewed by: bz >>> Differential Revision: https://reviews.freebsd.org/D46826 >>>=20 >>> (cherry picked from commit = b7cbf741d55468ba34305a14ac3acc1c286af034) >>> --- >>> sys/sys/libkern.h | 5 +---- >>> 1 file changed, 1 insertion(+), 4 deletions(-) >>>=20 >>> diff --git a/sys/sys/libkern.h b/sys/sys/libkern.h >>> index a10289d72dc7..835e5ffaf0b7 100644 >>> --- a/sys/sys/libkern.h >>> +++ b/sys/sys/libkern.h >>> @@ -229,10 +229,7 @@ ilog2_long_long(long long n) >>>=20 >>> #define ilog2(n) (__builtin_constant_p(n) ? ilog2_const(n) : = ilog2_var(n)) >>> #define rounddown_pow_of_two(n) ((__typeof(n))1 << ilog2(n)) >>> -#define order_base_2(n) ({ \ >>> - __typeof(n) _n =3D (n); \ >>=20 >> This local var `_n` is within the scope of the macro `order_base_2`, = it is surrounded with >> {} and is harmless, so it will not pollute the file scoped variables. >>=20 >> Am I reading the commit message wrong ? >=20 > It=E2=80=99s not about pollution. GNU statement expressions are just = not valid > at file scope, they must be used within a function (since otherwise = the > implementation would have to have a full blown interpreter to constant > evaluate the whole thing, just like C++ and now C to some extent have > ended up with these days with constexpr). >=20 > That is, you cannot write: >=20 > int x =3D ({ ... }); >=20 > at file scope. Ahh, I see. Thanks for the explaining! >=20 > Jess --Apple-Mail=_578F92E7-3BA6-4432-8E6C-74615E94D42A Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On Feb 11, 2025, at 1:23 PM, Jessica Clarke <jrtc27@freebsd.org> = wrote:

On 11 Feb 2025, at 03:30, Zhenlei Huang <zlei@FreeBSD.org> = wrote:
On Feb 10, 2025, at 7:15 = PM, Doug Moore <dougm@FreeBSD.org> wrote:

The branch stable/14 has been updated by dougm:

URL: https://cgit.FreeBSD.org/src/commit/?id=3D7bcc7a0b88ccb5e1fe31d= e88ab9a17e46859318b

commit = 7bcc7a0b88ccb5e1fe31de88ab9a17e46859318b
Author: =     Doug Moore <dougm@FreeBSD.org>
AuthorDate: 2024-09-27 23:43:07 +0000
Commit: =     Doug Moore <dougm@FreeBSD.org>
CommitDate: 2025-02-10 10:30:05 +0000

 libkern: avoid local var in order_base_2()

 order_base_2(n) is implemented with a = variable, which keeps it from
 being used at file = scope. Implement it instead as ilog2(2*n-1), which
 produces a different result when 2*n overflows, which = appears unlikely
 in practice.

 Reviewed by:    bz
 Differential Revision:  https://reviews.freebsd.org/D46826

 (cherry picked from commit = b7cbf741d55468ba34305a14ac3acc1c286af034)
---
sys/sys/libkern.h | 5 +----
1 file changed, 1 = insertion(+), 4 deletions(-)

diff --git = a/sys/sys/libkern.h b/sys/sys/libkern.h
index = a10289d72dc7..835e5ffaf0b7 100644
--- = a/sys/sys/libkern.h
+++ b/sys/sys/libkern.h
@@= -229,10 +229,7 @@ ilog2_long_long(long long n)

#define ilog2(n) (__builtin_constant_p(n) ? ilog2_const(n) : = ilog2_var(n))
#define rounddown_pow_of_two(n) = ((__typeof(n))1 << ilog2(n))
-#define = order_base_2(n) ({ \
- __typeof(n) _n =3D (n); \

This local var `_n` is within the = scope of the macro `order_base_2`, it is surrounded with
{} = and is harmless, so it will not pollute the file scoped variables.

Am I reading the commit message wrong ?

It=E2=80=99s not about pollution. GNU statement expressions = are just not valid
at file scope, they must be used within a function (since = otherwise the
implementation = would have to have a full blown interpreter to constant
evaluate the = whole thing, just like C++ and now C to some extent have
ended up with = these days with constexpr).

That is, you cannot write:

 int x =3D ({ ... });

at file scope.

Ahh, I see. Thanks for the explaining!


Jess



= --Apple-Mail=_578F92E7-3BA6-4432-8E6C-74615E94D42A--