[next,v2,5/5] minmax: Relax check to allow comparison between int and small unsigned constants.
Message ID | b4ce9dad748e489f9314a2dc95615033@AcuMS.aculab.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp512953vqg; Fri, 28 Jul 2023 08:28:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlGalN82hAb59DPpFqffCz5TcmX+ucrza3ONgpsVoGZ1oKljWOT5IphoAlbZXyykhYmtauEI X-Received: by 2002:a05:6a20:3ca7:b0:138:1a36:4eab with SMTP id b39-20020a056a203ca700b001381a364eabmr2825644pzj.3.1690558119383; Fri, 28 Jul 2023 08:28:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690558119; cv=none; d=google.com; s=arc-20160816; b=eElcJ+5KWWihBuIJvrrg9SbMbJ9tgCgqRJsEHQfI4cyxeqFuS8CAV0/eYWyqYdVblY 1hISMjHfH9y2xZs48ZYUcHH3D+DtHVmVAQzrEcAbBqJE5CoTSFDp4DCgZZvf2lGYp08F Ba2R/MKNMMKxUOjrx8J+KMqpPkhD3kcs49+HgzF9sC8xpe38DKtpcZN7/0H635Guy5J/ r+mRycP29LszD9z6pXhmSo9ZDFuDlURIgp182mSsWRHVv/WVzeR4nsJdclDa8UhUaN4Y PxsCzxmR5s+aK5zYH5LXeX49US+i/ULRV9RNWnV0UqQxpCwsD3HOZZ7EXJKGQ9nj0EIC TnyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:to:from; bh=a3h8hUQ/3lqZSO4t5xg7D+1zq28R8hrgYkseN62ofI4=; fh=lQu0FQMQB/KijsOLYPBSZ4oPXp6gJVSgtvs90PKCM00=; b=Q9zMTdtIErtf/fGz5hYCtgKXeXF4hRj9NUEd8z0wBFn+pPBLlsNVNZya/wh+0oM90X i3UG8yBgTUjJkK7F+gt8SbTTZDJBeF597aEWQzhP7UqpFS6SQH5Vv7x7y57N8uCsebYJ Fb/cXnqgc0bDjwaCvquGqvjO9AV5vtle52Kn3hMPLYpSzyzGiJkk9+rMLEFsA0/VpLPd bVY+pLrrHTlLQl1ILxQ0zWSx0PtlffYkklCzRc5fYkqWClLAAm2wS48I4uNed0/yFDBs A56mkyVgE3nPn3YBZJ4YvXLUFXlsxQSLcUbstiojxYjKgbNCsQH4c98YDjx7kvxaQhJH D1Rw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s21-20020a656455000000b00563eced0fe3si3194537pgv.232.2023.07.28.08.28.25; Fri, 28 Jul 2023 08:28:39 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237250AbjG1Oxn convert rfc822-to-8bit (ORCPT <rfc822;hanasaki@gmail.com> + 99 others); Fri, 28 Jul 2023 10:53:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229638AbjG1Oxm (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 28 Jul 2023 10:53:42 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D72FA12D for <linux-kernel@vger.kernel.org>; Fri, 28 Jul 2023 07:53:40 -0700 (PDT) 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-35-GHo7kd68Meqrvd_2dV5a8Q-1; Fri, 28 Jul 2023 15:53:37 +0100 X-MC-Unique: GHo7kd68Meqrvd_2dV5a8Q-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 28 Jul 2023 15:53:36 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Fri, 28 Jul 2023 15:53:36 +0100 From: David Laight <David.Laight@ACULAB.COM> To: "'linux-kernel@vger.kernel.org'" <linux-kernel@vger.kernel.org>, "'Andy Shevchenko'" <andriy.shevchenko@linux.intel.com>, 'Andrew Morton' <akpm@linux-foundation.org>, "'Matthew Wilcox (Oracle)'" <willy@infradead.org>, 'Christoph Hellwig' <hch@infradead.org>, "'Jason A. Donenfeld'" <Jason@zx2c4.com> Subject: [PATCH next v2 5/5] minmax: Relax check to allow comparison between int and small unsigned constants. Thread-Topic: [PATCH next v2 5/5] minmax: Relax check to allow comparison between int and small unsigned constants. Thread-Index: AdnBY0Y9GCHZV09FSTWgIDzdl1Lkkg== Date: Fri, 28 Jul 2023 14:53:36 +0000 Message-ID: <b4ce9dad748e489f9314a2dc95615033@AcuMS.aculab.com> References: <bde3d2dc933848bbaceeb9b7102f6f4c@AcuMS.aculab.com> In-Reply-To: <bde3d2dc933848bbaceeb9b7102f6f4c@AcuMS.aculab.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] 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: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772678670533346476 X-GMAIL-MSGID: 1772678670533346476 |
Series |
minmax: Relax type checks in min() and max().
|
|
Commit Message
David Laight
July 28, 2023, 2:53 p.m. UTC
Convert constants between 0 and INT_MAX to 'int' prior to comparisons
so that min(signed_var, 20u) and, more commonly, min(signed_var, sizeof())
are both valid.
Signed-off-by: David Laight <david.laight@aculab.com>
---
v2: Add cast to fix min/max with pointer types.
include/linux/minmax.h | 34 ++++++++++++++++++++++------------
1 file changed, 22 insertions(+), 12 deletions(-)
Comments
Hi David, kernel test robot noticed the following build warnings: [auto build test WARNING on akpm-mm/mm-everything] [also build test WARNING on linus/master crng-random/master v6.5-rc3 next-20230728] [cannot apply to next-20230728] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/David-Laight/minmax-Add-min_unsigned-a-b-and-max_unsigned-a-b/20230728-225439 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/b4ce9dad748e489f9314a2dc95615033%40AcuMS.aculab.com patch subject: [PATCH next v2 5/5] minmax: Relax check to allow comparison between int and small unsigned constants. config: alpha-randconfig-r024-20230727 (https://download.01.org/0day-ci/archive/20230729/202307290538.EtRKfGgC-lkp@intel.com/config) compiler: alpha-linux-gcc (GCC) 12.3.0 reproduce: (https://download.01.org/0day-ci/archive/20230729/202307290538.EtRKfGgC-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202307290538.EtRKfGgC-lkp@intel.com/ All warnings (new ones prefixed by >>): In file included from include/linux/kernel.h:27, from include/linux/cpumask.h:10, from include/linux/mm_types_task.h:14, from include/linux/mm_types.h:5, from include/linux/buildid.h:5, from include/linux/module.h:14, from net/ceph/osdmap.c:5: net/ceph/osdmap.c: In function 'osdmap_decode': >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:39:27: note: in definition of macro '__cmp' 39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) | ^ include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int' 28 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:50:27: note: in expansion of macro '__int_const' 50 | __cmp(op, __int_const(x), __int_const(y)), \ | ^~~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:1773:54: note: in expansion of macro 'min' 1773 | err = osdmap_set_crush(map, crush_decode(*p, min(*p + len, end))); | ^~~ >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:39:45: note: in definition of macro '__cmp' 39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) | ^ include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int' 28 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:50:43: note: in expansion of macro '__int_const' 50 | __cmp(op, __int_const(x), __int_const(y)), \ | ^~~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:1773:54: note: in expansion of macro 'min' 1773 | err = osdmap_set_crush(map, crush_decode(*p, min(*p + len, end))); | ^~~ >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:39:51: note: in definition of macro '__cmp' 39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) | ^ include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int' 28 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:50:27: note: in expansion of macro '__int_const' 50 | __cmp(op, __int_const(x), __int_const(y)), \ | ^~~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:1773:54: note: in expansion of macro 'min' 1773 | err = osdmap_set_crush(map, crush_decode(*p, min(*p + len, end))); | ^~~ >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:39:57: note: in definition of macro '__cmp' 39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) | ^ include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int' 28 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:50:43: note: in expansion of macro '__int_const' 50 | __cmp(op, __int_const(x), __int_const(y)), \ | ^~~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:1773:54: note: in expansion of macro 'min' 1773 | err = osdmap_set_crush(map, crush_decode(*p, min(*p + len, end))); | ^~~ >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int' 28 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:42:16: note: in expansion of macro '__int_const' 42 | typeof(__int_const(x)) unique_x = (x); \ | ^~~~~~~~~~~ include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once' 51 | __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) | ^~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:1773:54: note: in expansion of macro 'min' 1773 | err = osdmap_set_crush(map, crush_decode(*p, min(*p + len, end))); | ^~~ >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int' 28 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:43:16: note: in expansion of macro '__int_const' 43 | typeof(__int_const(y)) unique_y = (y); \ | ^~~~~~~~~~~ include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once' 51 | __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) | ^~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:1773:54: note: in expansion of macro 'min' 1773 | err = osdmap_set_crush(map, crush_decode(*p, min(*p + len, end))); | ^~~ In file included from include/linux/container_of.h:5, from include/linux/list.h:5, from include/linux/module.h:12: >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert' 78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg) | ^~~~ include/linux/minmax.h:44:9: note: in expansion of macro 'static_assert' 44 | static_assert(__types_ok(x, y), \ | ^~~~~~~~~~~~~ include/linux/minmax.h:34:17: note: in expansion of macro '__is_noneg_int' 34 | __is_noneg_int(x) || __is_noneg_int(y)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:44:23: note: in expansion of macro '__types_ok' 44 | static_assert(__types_ok(x, y), \ | ^~~~~~~~~~ include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once' 51 | __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) | ^~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:1773:54: note: in expansion of macro 'min' 1773 | err = osdmap_set_crush(map, crush_decode(*p, min(*p + len, end))); | ^~~ >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert' 78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg) | ^~~~ include/linux/minmax.h:44:9: note: in expansion of macro 'static_assert' 44 | static_assert(__types_ok(x, y), \ | ^~~~~~~~~~~~~ include/linux/minmax.h:34:38: note: in expansion of macro '__is_noneg_int' 34 | __is_noneg_int(x) || __is_noneg_int(y)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:44:23: note: in expansion of macro '__types_ok' 44 | static_assert(__types_ok(x, y), \ | ^~~~~~~~~~ include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once' 51 | __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) | ^~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:1773:54: note: in expansion of macro 'min' 1773 | err = osdmap_set_crush(map, crush_decode(*p, min(*p + len, end))); | ^~~ net/ceph/osdmap.c: In function 'osdmap_apply_incremental': >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:39:27: note: in definition of macro '__cmp' 39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) | ^ include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int' 28 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:50:27: note: in expansion of macro '__int_const' 50 | __cmp(op, __int_const(x), __int_const(y)), \ | ^~~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:2000:46: note: in expansion of macro 'min' 2000 | return ceph_osdmap_decode(p, min(*p+len, end), msgr2); | ^~~ >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:39:45: note: in definition of macro '__cmp' 39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) | ^ include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int' 28 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:50:43: note: in expansion of macro '__int_const' 50 | __cmp(op, __int_const(x), __int_const(y)), \ | ^~~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:2000:46: note: in expansion of macro 'min' 2000 | return ceph_osdmap_decode(p, min(*p+len, end), msgr2); | ^~~ >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:39:51: note: in definition of macro '__cmp' 39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) | ^ include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int' 28 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:50:27: note: in expansion of macro '__int_const' 50 | __cmp(op, __int_const(x), __int_const(y)), \ | ^~~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:2000:46: note: in expansion of macro 'min' 2000 | return ceph_osdmap_decode(p, min(*p+len, end), msgr2); | ^~~ >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:39:57: note: in definition of macro '__cmp' 39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) | ^ include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int' 28 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:50:43: note: in expansion of macro '__int_const' 50 | __cmp(op, __int_const(x), __int_const(y)), \ | ^~~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:2000:46: note: in expansion of macro 'min' 2000 | return ceph_osdmap_decode(p, min(*p+len, end), msgr2); | ^~~ >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int' 28 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:42:16: note: in expansion of macro '__int_const' 42 | typeof(__int_const(x)) unique_x = (x); \ | ^~~~~~~~~~~ include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once' 51 | __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) | ^~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:2000:46: note: in expansion of macro 'min' 2000 | return ceph_osdmap_decode(p, min(*p+len, end), msgr2); | ^~~ >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int' 28 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:43:16: note: in expansion of macro '__int_const' 43 | typeof(__int_const(y)) unique_y = (y); \ | ^~~~~~~~~~~ include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once' 51 | __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) | ^~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:2000:46: note: in expansion of macro 'min' 2000 | return ceph_osdmap_decode(p, min(*p+len, end), msgr2); | ^~~ >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert' 78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg) | ^~~~ include/linux/minmax.h:44:9: note: in expansion of macro 'static_assert' 44 | static_assert(__types_ok(x, y), \ | ^~~~~~~~~~~~~ include/linux/minmax.h:34:17: note: in expansion of macro '__is_noneg_int' 34 | __is_noneg_int(x) || __is_noneg_int(y)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:44:23: note: in expansion of macro '__types_ok' 44 | static_assert(__types_ok(x, y), \ | ^~~~~~~~~~ include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once' 51 | __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) | ^~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:2000:46: note: in expansion of macro 'min' 2000 | return ceph_osdmap_decode(p, min(*p+len, end), msgr2); | ^~~ >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert' 78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg) | ^~~~ include/linux/minmax.h:44:9: note: in expansion of macro 'static_assert' 44 | static_assert(__types_ok(x, y), \ | ^~~~~~~~~~~~~ include/linux/minmax.h:34:38: note: in expansion of macro '__is_noneg_int' 34 | __is_noneg_int(x) || __is_noneg_int(y)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:44:23: note: in expansion of macro '__types_ok' 44 | static_assert(__types_ok(x, y), \ | ^~~~~~~~~~ include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once' 51 | __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) | ^~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:2000:46: note: in expansion of macro 'min' 2000 | return ceph_osdmap_decode(p, min(*p+len, end), msgr2); | ^~~ >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:39:27: note: in definition of macro '__cmp' 39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) | ^ include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int' 28 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:50:27: note: in expansion of macro '__int_const' 50 | __cmp(op, __int_const(x), __int_const(y)), \ | ^~~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:2007:57: note: in expansion of macro 'min' 2007 | crush_decode(*p, min(*p + len, end))); | ^~~ >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:39:45: note: in definition of macro '__cmp' 39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) | ^ include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int' 28 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:50:43: note: in expansion of macro '__int_const' 50 | __cmp(op, __int_const(x), __int_const(y)), \ | ^~~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:2007:57: note: in expansion of macro 'min' 2007 | crush_decode(*p, min(*p + len, end))); | ^~~ >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:39:51: note: in definition of macro '__cmp' 39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) | ^ include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int' 28 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:50:27: note: in expansion of macro '__int_const' 50 | __cmp(op, __int_const(x), __int_const(y)), \ | ^~~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:2007:57: note: in expansion of macro 'min' 2007 | crush_decode(*p, min(*p + len, end))); | ^~~ >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:39:57: note: in definition of macro '__cmp' 39 | #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) | ^ include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int' 28 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:50:43: note: in expansion of macro '__int_const' 50 | __cmp(op, __int_const(x), __int_const(y)), \ | ^~~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:2007:57: note: in expansion of macro 'min' 2007 | crush_decode(*p, min(*p + len, end))); | ^~~ include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int' 28 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:42:16: note: in expansion of macro '__int_const' 42 | typeof(__int_const(x)) unique_x = (x); \ | ^~~~~~~~~~~ include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once' 51 | __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) | ^~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:2007:57: note: in expansion of macro 'min' 2007 | crush_decode(*p, min(*p + len, end))); | ^~~ include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/minmax.h:28:47: note: in expansion of macro '__is_noneg_int' 28 | #define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:43:16: note: in expansion of macro '__int_const' 43 | typeof(__int_const(y)) unique_y = (y); \ | ^~~~~~~~~~~ include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once' 51 | __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) | ^~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:2007:57: note: in expansion of macro 'min' 2007 | crush_decode(*p, min(*p + len, end))); | ^~~ include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert' 78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg) | ^~~~ include/linux/minmax.h:44:9: note: in expansion of macro 'static_assert' 44 | static_assert(__types_ok(x, y), \ | ^~~~~~~~~~~~~ include/linux/minmax.h:34:17: note: in expansion of macro '__is_noneg_int' 34 | __is_noneg_int(x) || __is_noneg_int(y)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:44:23: note: in expansion of macro '__types_ok' 44 | static_assert(__types_ok(x, y), \ | ^~~~~~~~~~ include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once' 51 | __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) | ^~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:2007:57: note: in expansion of macro 'min' 2007 | crush_decode(*p, min(*p + len, end))); | ^~~ include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) | ^~ include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert' 78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg) | ^~~~ include/linux/minmax.h:44:9: note: in expansion of macro 'static_assert' 44 | static_assert(__types_ok(x, y), \ | ^~~~~~~~~~~~~ include/linux/minmax.h:34:38: note: in expansion of macro '__is_noneg_int' 34 | __is_noneg_int(x) || __is_noneg_int(y)) | ^~~~~~~~~~~~~~ include/linux/minmax.h:44:23: note: in expansion of macro '__types_ok' 44 | static_assert(__types_ok(x, y), \ | ^~~~~~~~~~ include/linux/minmax.h:51:17: note: in expansion of macro '__cmp_once' 51 | __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) | ^~~~~~~~~~ include/linux/minmax.h:78:25: note: in expansion of macro '__careful_cmp' 78 | #define min(x, y) __careful_cmp(min, x, y) | ^~~~~~~~~~~~~ net/ceph/osdmap.c:2007:57: note: in expansion of macro 'min' 2007 | crush_decode(*p, min(*p + len, end))); .. vim +26 include/linux/minmax.h 7 8 /* 9 * min()/max()/clamp() macros must accomplish three things: 10 * 11 * - Avoid multiple evaluations of the arguments (so side-effects like 12 * "x++" happen only once) when non-constant. 13 * - Perform signed v unsigned type-checking (to generate compile 14 * errors instead of nasty runtime surprises). 15 * Constants from 0 to INT_MAX are cast to (int) so can be used 16 * in comparisons with signed types. 17 * - Retain result as a constant expressions when called with only 18 * constant expressions (to avoid tripping VLA warnings in stack 19 * allocation usage). 20 */ 21 #define __typecheck(x, y) \ 22 (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1))) 23 24 #define __is_noneg_int(x) \ 25 __builtin_choose_expr(!__is_constexpr(x), false, \ > 26 ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) 27
From: kernel test robot > Sent: 28 July 2023 22:43 > > kernel test robot noticed the following build warnings: > > [auto build test WARNING on akpm-mm/mm-everything] > [also build test WARNING on linus/master crng-random/master v6.5-rc3 next-20230728] > [cannot apply to next-20230728] > [If your patch is applied to the wrong git tree, kindly drop us a note. > And when submitting patch, we suggest to use '--base' as documented in > https://git-scm.com/docs/git-format-patch#_base_tree_information] > > url: https://github.com/intel-lab-lkp/linux/commits/David-Laight/minmax-Add-min_unsigned-a-b-and- > max_unsigned-a-b/20230728-225439 > base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything > patch link: https://lore.kernel.org/r/b4ce9dad748e489f9314a2dc95615033%40AcuMS.aculab.com > patch subject: [PATCH next v2 5/5] minmax: Relax check to allow comparison between int and small > unsigned constants. > config: alpha-randconfig-r024-20230727 (https://download.01.org/0day- > ci/archive/20230729/202307290538.EtRKfGgC-lkp@intel.com/config) > compiler: alpha-linux-gcc (GCC) 12.3.0 > reproduce: (https://download.01.org/0day-ci/archive/20230729/202307290538.EtRKfGgC- > lkp@intel.com/reproduce) > > If you fix the issue in a separate patch/commit (i.e. not just a new version of > the same patch/commit), kindly add following tags > | Reported-by: kernel test robot <lkp@intel.com> > | Closes: https://lore.kernel.org/oe-kbuild-all/202307290538.EtRKfGgC-lkp@intel.com/ > > All warnings (new ones prefixed by >>): > > In file included from include/linux/kernel.h:27, > from include/linux/cpumask.h:10, > from include/linux/mm_types_task.h:14, > from include/linux/mm_types.h:5, > from include/linux/buildid.h:5, > from include/linux/module.h:14, > from net/ceph/osdmap.c:5: > net/ceph/osdmap.c: In function 'osdmap_decode': > >> include/linux/minmax.h:26:22: warning: ordered comparison of pointer with null pointer [-Wextra] > 26 | ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) I have a cunning plan to fix this (and warnings about testing 'unsigned >= 0'). Basically replace the first test with: __builtin_choose_expr(is_signed(x), x, 1) >= 0 (Also fixes the build with clang < 16.) Hopefully that v3 will keep the build robert happy :-) David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
By the time I've done: #define __is_noneg_int(x) \ __builtin_choose_expr(!__is_constexpr(x), false, \ ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) #define __is_signed(x) \ __builtin_choose_expr(__is_constexpr(is_signed_type(typeof(x))), \ is_signed_type(typeof(x)), 0) #define __types_ok(x, y) \ (__is_signed(x) == __is_signed(y) || \ __is_signed((x) + 0) == __is_signed((y) + 0) || \ __is_noneg_int(x) || __is_noneg_int(y)) the error message for > static_assert(__types_ok(x, y), \ > #op "(" #x ", " #y ") signedness error, fix types or consider " #op "_unsigned() before " #op "_t()"); \ generated by clang 8.0.0 and later is similar to (see https://godbolt.org/z/jq613Gnsa): <source>:49:12: error: static assertion failed due to requirement '__builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((int)(-1)) < (int)1)) * 0L)) : (int *)8))), (((int)(-1)) < (int)1), 0) == __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((unsigned int)(-1)) < (unsigned int)1)) * 0L)) : (int *)8))), (((unsigned int)(-1)) < (unsigned int)1), 0) || __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((int)(-1)) < (int)1)) * 0L)) : (int *)8))), (((int)(-1)) < (int)1), 0) == __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((unsigned int)(-1)) < (unsigned int)1)) * 0L)) : (int *)8))), (((unsigned int)(-1)) < (unsigned int)1), 0) || (__builtin_choose_expr(!(sizeof(int) == sizeof (*(8 ? ((void *)((long)(a) * 0L)) : (int *)8))), 0, __builtin_choose_expr(__builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((int)(-1)) < (int)1)) * 0L)) : (int *)8))), (((int)(-1)) < (int)1), 0), a, 0) >= 0 && (a) <= (int)(long)2147483647)) || (__builtin_choose_expr(!(sizeof(int) == sizeof (*(8 ? ((void *)((long)(2147483648U - 0) * 0L)) : (int *)8))), 0, __builtin_choose_expr(__builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((unsigned int)(-1)) < (unsigned int)1)) * 0L)) : (int *)8))), (((unsigned int)(-1)) < (unsigned int)1), 0), 2147483648U - 0, 0) >= 0 && (2147483648U - 0) <= (unsigned int)(long)2147483647))': min(a, 0x80000000u - 0) signedness error, fix types or consider min_unsigned() before min_t() Repeating the expression seems somewhat sub-optimal! Surely it shouldn't be outputting the expansion of the input when an error message is supplied? Is there any (sane) way to stop it being that verbose? David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
On Mon, Jul 31, 2023 at 6:27 AM David Laight <David.Laight@aculab.com> wrote: > > By the time I've done: > > #define __is_noneg_int(x) \ > __builtin_choose_expr(!__is_constexpr(x), false, \ > ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) > > #define __is_signed(x) \ > __builtin_choose_expr(__is_constexpr(is_signed_type(typeof(x))), \ > is_signed_type(typeof(x)), 0) > > #define __types_ok(x, y) \ > (__is_signed(x) == __is_signed(y) || \ > __is_signed((x) + 0) == __is_signed((y) + 0) || \ > __is_noneg_int(x) || __is_noneg_int(y)) > > the error message for > > > static_assert(__types_ok(x, y), \ > > #op "(" #x ", " #y ") signedness error, fix types or consider " #op "_unsigned() before " #op "_t()"); \ > > generated by clang 8.0.0 and later is similar to (see https://godbolt.org/z/jq613Gnsa): > > <source>:49:12: error: static assertion failed due to requirement '__builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((int)(-1)) < (int)1)) * 0L)) : (int *)8))), (((int)(-1)) < (int)1), 0) == __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((unsigned int)(-1)) < (unsigned int)1)) * 0L)) : (int *)8))), (((unsigned int)(-1)) < (unsigned int)1), 0) || __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((int)(-1)) < (int)1)) * 0L)) : (int *)8))), (((int)(-1)) < (int)1), 0) == __builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((unsigned int)(-1)) < (unsigned int)1)) * 0L)) : (int *)8))), (((unsigned int)(-1)) < (unsigned int)1), 0) || (__builtin_choose_expr(!(sizeof(int) == sizeof (*(8 ? ((void *)((long)(a) * 0L)) : (int *)8))), 0, __builtin_choose_expr(__builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((int)(-1)) < (int)1)) * 0L)) : (int *)8))), (((int)(-1)) < (int)1), 0), a, 0) >= 0 && (a) <= (int)(long)2147483647)) || (__builtin_choose_expr(!(sizeof(int) == sizeof (*(8 ? ((void *)((long)(2147483648U - 0) * 0L)) : (int *)8))), 0, __builtin_choose_expr(__builtin_choose_expr((sizeof(int) == sizeof (*(8 ? ((void *)((long)((((unsigned int)(-1)) < (unsigned int)1)) * 0L)) : (int *)8))), (((unsigned int)(-1)) < (unsigned int)1), 0), 2147483648U - 0, 0) >= 0 && (2147483648U - 0) <= (unsigned int)(long)2147483647))': min(a, 0x80000000u - 0) signedness error, fix types or consider min_unsigned() before min_t() > > Repeating the expression seems somewhat sub-optimal! > Surely it shouldn't be outputting the expansion of the > input when an error message is supplied? > > Is there any (sane) way to stop it being that verbose? No, but we can probably change that in clang. Filed: https://github.com/llvm/llvm-project/issues/64310 > > David > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > Registration No: 1397386 (Wales)
diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 7d3ad9cbbff6..28edafb3dcca 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -8,20 +8,30 @@ /* * min()/max()/clamp() macros must accomplish three things: * - * - avoid multiple evaluations of the arguments (so side-effects like + * - Avoid multiple evaluations of the arguments (so side-effects like * "x++" happen only once) when non-constant. - * - perform signed v unsigned type-checking (to generate compile + * - Perform signed v unsigned type-checking (to generate compile * errors instead of nasty runtime surprises). - * - retain result as a constant expressions when called with only + * Constants from 0 to INT_MAX are cast to (int) so can be used + * in comparisons with signed types. + * - Retain result as a constant expressions when called with only * constant expressions (to avoid tripping VLA warnings in stack * allocation usage). */ #define __typecheck(x, y) \ (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1))) -#define __types_ok(x, y) \ - (is_signed_type(typeof(x)) == is_signed_type(typeof(y)) || \ - is_signed_type(typeof((x) + 0)) == is_signed_type(typeof((y) + 0))) +#define __is_noneg_int(x) \ + __builtin_choose_expr(!__is_constexpr(x), false, \ + ((x) >= (typeof(x))0 && (x) <= (typeof((x) + 0))(long)__INT_MAX__)) + +#define __int_const(x) __builtin_choose_expr(__is_noneg_int(x), (int)(long)(x), (x)) + +#define __is_signed(x) is_signed_type(typeof(x)) +#define __types_ok(x, y) \ + (__is_signed(x) == __is_signed(y) || \ + __is_signed((x) + 0) == __is_signed((y) + 0) || \ + __is_noneg_int(x) || __is_noneg_int(y)) #define __cmp_op_min < #define __cmp_op_max > @@ -29,24 +39,24 @@ #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) #define __cmp_once(op, x, y, unique_x, unique_y) ({ \ - typeof(x) unique_x = (x); \ - typeof(y) unique_y = (y); \ + typeof(__int_const(x)) unique_x = (x); \ + typeof(__int_const(y)) unique_y = (y); \ static_assert(__types_ok(x, y), \ #op "(" #x ", " #y ") signedness error, fix types or consider " #op "_unsigned() before " #op "_t()"); \ __cmp(op, unique_x, unique_y); }) #define __careful_cmp(op, x, y) \ __builtin_choose_expr(__is_constexpr((x) - (y)), \ - __cmp(op, x, y), \ + __cmp(op, __int_const(x), __int_const(y)), \ __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) #define __clamp(val, lo, hi) \ ((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val))) #define __clamp_once(val, lo, hi, unique_val, unique_lo, unique_hi) ({ \ - typeof(val) unique_val = (val); \ - typeof(lo) unique_lo = (lo); \ - typeof(hi) unique_hi = (hi); \ + typeof(__int_const(val)) unique_val = (val); \ + typeof(__int_const(lo)) unique_lo = (lo); \ + typeof(__int_const(hi)) unique_hi = (hi); \ static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \ (lo) <= (hi), true), \ "clamp() low limit " #lo " greater than high limit " #hi); \