Message ID | 8059bc04da1a45bc810ac339a1129a4c@AcuMS.aculab.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-80210-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1656590dyb; Sun, 25 Feb 2024 08:49:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUjT0og53IBSw414zTSW2CZmOGUd82eu4kd1ZVSqi5AS0yXB9km+AsJ7bkgXxPY4rMCgXnemBIUh0h8PwkU28hmq80K3A== X-Google-Smtp-Source: AGHT+IFDB1ZF9qO6MyicHOkVMxuFTJ7ijFBPxFpuALxwbVstfWoIgucetjddlmkWM5ldKguOlDXc X-Received: by 2002:a05:6402:1607:b0:564:71:ccf0 with SMTP id f7-20020a056402160700b005640071ccf0mr3325519edv.2.1708879779183; Sun, 25 Feb 2024 08:49:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708879779; cv=pass; d=google.com; s=arc-20160816; b=BHj1nfyiTkzYsOhBoUyv462vpomdd/pT5fqYWVL43/GdQf07SHd2gM8CnLiBmfhBhV DtnCwz2fHHSuK+OZgQGS0VjCpR7otfSgNnOuAFKS+37DjCRCCZP3GFXeeMNPvym9aHru m/rxUY4BbMiNoktMfDsEYDNe4lf6iqduKaFA0C/1cao5UcSzAnrWMOmcSHiWEVZbQk9a z+lQN53ICeSl4++WWT8IQQw8QfvuGQKXty2kv5uPBchiVQUewjX9c/GS9y3VJoJCYXaM JKYG8irqk3byzECVz1n0vANEFrJ0gwG/FX41pyQ4ouuCPhf7sichgb5ZkVYya+0HH3KE Oz3g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:accept-language :in-reply-to:references:message-id:date:thread-index:thread-topic :subject:cc:to:from; bh=C3LKmkJkN8dkZ0RHNjijjC6uoAGGE0xrQwkKifLFDjY=; fh=nGE692sbVdRvha6RYbzMUXtm1nr/30sV7frdtDN2z14=; b=W9OZoznk4+vsB/oXbrBL02QFc26saYcso9kmtn7l6t4jpfGjfcpZDB1dCHjSM+yKHX pwuKsoGI2Jg8n8xsBUBpjge7h2QyT1hQx4XfRvoCjD1Om3EkB5BaH4JHNtZ1i8erkxsU StzdaZ6wi16LWhyaui4NbqCmswfiF22B1VODnEQ2mwYklafBHHQMiul3EJl5jelyobD0 ovUGpFEUvsgNmI8LTFUxJapDC5rnxRUOULZhRp+/vosOzlCWLLvOv8898v11Jg+tAm4F dJxKHSFSbnK3W2NSLcok817ZFTFKaKp/k0HziOhWjc4BQ1mq66UqHWp3gcVICbm1X288 JuHw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=aculab.com dmarc=pass fromdomain=aculab.com); spf=pass (google.com: domain of linux-kernel+bounces-80210-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80210-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u29-20020a50c05d000000b0056568fe52eesi1335110edd.565.2024.02.25.08.49.39 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 08:49:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80210-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=aculab.com dmarc=pass fromdomain=aculab.com); spf=pass (google.com: domain of linux-kernel+bounces-80210-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80210-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id CA6C21F21403 for <ouuuleilei@gmail.com>; Sun, 25 Feb 2024 16:49:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3DA1C18B1A; Sun, 25 Feb 2024 16:49:18 +0000 (UTC) Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6F1817BB4 for <linux-kernel@vger.kernel.org>; Sun, 25 Feb 2024 16:49:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.58.85.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708879756; cv=none; b=YhFVnCO1KG4SfpOkaFiyXo6SbWf7/McgetMCsy/LeF/fE3HrNDCCJeLwWJgipYzDSo9qqH9hQGPkEkZpdIZVGuRdImKUM9G9VZAkeht6QAvmcxTqvK8W9pIWKeGxKQK5gc7GbrXYqAxxe0mTlYnHOOgzOcdvRh4wXOwcB8zPbtA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708879756; c=relaxed/simple; bh=8ye8TjxJr7Qpfxmc8F8Nww5LIwfQZHhRr6Lbkiz0KUc=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: MIME-Version:Content-Type; b=FD3/YCHf1VYBsHaK3/U/wD9/GlO1iT9k3yxql8h62cl0T5XwggnJOPTFu4/hm7Q198NSEkfk2O1MYUh4SNum1ElmcL3PBb04GBwwboCXO4iZEmNIM1PBj84oyXAbJ1OFJnhWWiIoWqO2MARt07kxFIi2FM3mSxXzlQ0OpJWTZNs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM; spf=pass smtp.mailfrom=aculab.com; arc=none smtp.client-ip=185.58.85.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aculab.com Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-198-BfGlJeiVOxaAMdciN2scyQ-1; Sun, 25 Feb 2024 16:49:11 +0000 X-MC-Unique: BfGlJeiVOxaAMdciN2scyQ-1 Received: from AcuMS.Aculab.com (10.202.163.6) by AcuMS.aculab.com (10.202.163.6) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sun, 25 Feb 2024 16:49:10 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 25 Feb 2024 16:49:10 +0000 From: David Laight <David.Laight@ACULAB.COM> To: "'linux-kernel@vger.kernel.org'" <linux-kernel@vger.kernel.org>, "'Linus Torvalds'" <torvalds@linux-foundation.org>, 'Netdev' <netdev@vger.kernel.org>, "'dri-devel@lists.freedesktop.org'" <dri-devel@lists.freedesktop.org> CC: 'Jens Axboe' <axboe@kernel.dk>, "'Matthew Wilcox (Oracle)'" <willy@infradead.org>, 'Christoph Hellwig' <hch@infradead.org>, "'linux-btrfs@vger.kernel.org'" <linux-btrfs@vger.kernel.org>, "'Andrew Morton'" <akpm@linux-foundation.org>, 'Andy Shevchenko' <andriy.shevchenko@linux.intel.com>, "'David S . Miller'" <davem@davemloft.net>, 'Dan Carpenter' <dan.carpenter@linaro.org>, "'Jani Nikula'" <jani.nikula@linux.intel.com> Subject: [PATCH next v2 02/11] minmax: Use _Static_assert() instead of static_assert() Thread-Topic: [PATCH next v2 02/11] minmax: Use _Static_assert() instead of static_assert() Thread-Index: AdpoComWnYboZopTTWeIFfAWCv2rOw== Date: Sun, 25 Feb 2024 16:49:10 +0000 Message-ID: <8059bc04da1a45bc810ac339a1129a4c@AcuMS.aculab.com> References: <0fff52305e584036a777f440b5f474da@AcuMS.aculab.com> In-Reply-To: <0fff52305e584036a777f440b5f474da@AcuMS.aculab.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791890323156389268 X-GMAIL-MSGID: 1791890323156389268 |
Series |
minmax: Optimise to reduce .i line length
|
|
Commit Message
David Laight
Feb. 25, 2024, 4:49 p.m. UTC
The wrapper just adds two more lines of error output when the test fails.
Signed-off-by: David Laight <david.laight@aculab.com>
---
include/linux/minmax.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
Changes for v2:
- Typographical and spelling corrections to the commit messages.
Patches unchanged.
Comments
On Sun, 25 Feb 2024, David Laight <David.Laight@ACULAB.COM> wrote: > The wrapper just adds two more lines of error output when the test fails. There are only a handful of places in kernel code that use _Static_assert() directly. Nearly 900 instances of static_assert(). Are we now saying it's fine to use _Static_assert() directly all over the place? People will copy-paste and cargo cult. BR, Jani. > > Signed-off-by: David Laight <david.laight@aculab.com> > --- > include/linux/minmax.h | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > Changes for v2: > - Typographical and spelling corrections to the commit messages. > Patches unchanged. > > diff --git a/include/linux/minmax.h b/include/linux/minmax.h > index 63c45865b48a..900eec7a28e5 100644 > --- a/include/linux/minmax.h > +++ b/include/linux/minmax.h > @@ -48,7 +48,7 @@ > #define __cmp_once(op, x, y, unique_x, unique_y) ({ \ > typeof(x) unique_x = (x); \ > typeof(y) unique_y = (y); \ > - static_assert(__types_ok(x, y), \ > + _Static_assert(__types_ok(x, y), \ > #op "(" #x ", " #y ") signedness error, fix types or consider u" #op "() before " #op "_t()"); \ > __cmp(op, unique_x, unique_y); }) > > @@ -137,11 +137,11 @@ > typeof(val) unique_val = (val); \ > typeof(lo) unique_lo = (lo); \ > typeof(hi) unique_hi = (hi); \ > - static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \ > + _Static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \ > (lo) <= (hi), true), \ > "clamp() low limit " #lo " greater than high limit " #hi); \ > - static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error"); \ > - static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error"); \ > + _Static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error"); \ > + _Static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error"); \ > __clamp(unique_val, unique_lo, unique_hi); }) > > #define __careful_clamp(val, lo, hi) ({ \
From: Jani Nikula > Sent: 26 February 2024 09:28 > > On Sun, 25 Feb 2024, David Laight <David.Laight@ACULAB.COM> wrote: > > The wrapper just adds two more lines of error output when the test fails. > > There are only a handful of places in kernel code that use > _Static_assert() directly. Nearly 900 instances of static_assert(). How many of those supply an error message? > Are we now saying it's fine to use _Static_assert() directly all over > the place? People will copy-paste and cargo cult. Is that actually a problem? The wrapper allows the error message to be omitted and substitutes the text of the conditional. But it isn't 'free'. As well as slightly slowing down the compilation, the error messages from the compiler get more difficult to interpret. Most of the static_assert() will probably never generate an error. But the ones in min()/max() will so it is best to make them as readable as possible. (Don't even look as the mess clang makes....) David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
On Mon, 26 Feb 2024, David Laight <David.Laight@ACULAB.COM> wrote: > From: Jani Nikula >> Sent: 26 February 2024 09:28 >> >> On Sun, 25 Feb 2024, David Laight <David.Laight@ACULAB.COM> wrote: >> > The wrapper just adds two more lines of error output when the test fails. >> >> There are only a handful of places in kernel code that use >> _Static_assert() directly. Nearly 900 instances of static_assert(). > > How many of those supply an error message? At a glance, not many. >> Are we now saying it's fine to use _Static_assert() directly all over >> the place? People will copy-paste and cargo cult. > > Is that actually a problem? I don't know. I'm asking. Usually when we have compiler wrappers, they're meant to be used instead of the thing being wrapped. This series deviates from that, so it would seem to fair to mention it slightly more verbosely than just stating what's being done. > The wrapper allows the error message to be omitted and substitutes > the text of the conditional. > But it isn't 'free'. > As well as slightly slowing down the compilation, the error messages > from the compiler get more difficult to interpret. > > Most of the static_assert() will probably never generate an error. > But the ones in min()/max() will so it is best to make them as > readable as possible. > (Don't even look as the mess clang makes....) I'm not arguing any of this. :) BR, Jani.
diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 63c45865b48a..900eec7a28e5 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -48,7 +48,7 @@ #define __cmp_once(op, x, y, unique_x, unique_y) ({ \ typeof(x) unique_x = (x); \ typeof(y) unique_y = (y); \ - static_assert(__types_ok(x, y), \ + _Static_assert(__types_ok(x, y), \ #op "(" #x ", " #y ") signedness error, fix types or consider u" #op "() before " #op "_t()"); \ __cmp(op, unique_x, unique_y); }) @@ -137,11 +137,11 @@ typeof(val) unique_val = (val); \ typeof(lo) unique_lo = (lo); \ typeof(hi) unique_hi = (hi); \ - static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \ + _Static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \ (lo) <= (hi), true), \ "clamp() low limit " #lo " greater than high limit " #hi); \ - static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error"); \ - static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error"); \ + _Static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error"); \ + _Static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error"); \ __clamp(unique_val, unique_lo, unique_hi); }) #define __careful_clamp(val, lo, hi) ({ \