From patchwork Thu Jan 4 19:47:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 759870 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp7153309wrw; Thu, 4 Jan 2024 11:48:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGQly9Ed6bu1wgZND9SxNDS8868KkIlrrBdQx/cgZkGuMJIQlQntHAqRCnVr6ceD/+NiHPE X-Received: by 2002:ad4:5aa1:0:b0:67f:309f:256d with SMTP id u1-20020ad45aa1000000b0067f309f256dmr1426480qvg.7.1704397713740; Thu, 04 Jan 2024 11:48:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704397713; cv=pass; d=google.com; s=arc-20160816; b=cvWkmV/eG6QVwUiTycbNRsE8Y5//JCXPEDQ0B2v2ZZCMMVWJlpjVvBvbf+k5JqJ1u/ uH0ctX7ubKVxSV0n/+prT/HYfH5SyyNZt+h5anQjhsDKqwixqo4VCUx7GXoIkpLTIS/z Yq6KuebcOKsr58aFoigZGDBcVEwPZs7u+ZR5GlWn9myJfUEBzA+b6284sAsaHCaGvnwU WDamkEhhMlUIbx5GV+k0QzRdSJWUsBiWNPcoq3xiFMTFGdd9EGcvhIqhKVqvPB3Q5enp ytE3ZXTVlyAO//dOffHoPoDjRhmhrwMqDgWGJMUOtLx0hNWHqZL2YyED5C5kx+vn53CW lc6A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=WBgC4HIExLUhoWDbS4Q25u3oB98vuNk9TA71wKsrAkM=; fh=w4YPogs5qr06moNsiHAOaMGems29oYfgLzW3XNbqAJI=; b=Gr2oCpoYkOiiWQHz2AZX+HF00auytkPR7XGYgkeeem067zOC9WOtLHSYgbB1A2oZhO YKynpu3fF0tBgH4YdUybyOfh0VcgKqQWPT5tRYY0fltCX8mip44vRXgrFYHqCGoNgDkY Wle7uXi/0IrbplgNFaooV4QCNJduR5M3a9iXi64QWd+4LKdphHk3QuFJPJQCWnQGLoXw Aafq8UsM3Tb1bXJTok1ZSOeFCq2IxRbdOjUWZhXgPvQ/hyeNCRJ1GgDDI8t9tCTm2uxO iM89Z9tNmUNqkEZOt2G6DHh8T7qmHEkKD1X3QMkKa0OoVILE/Thm98QrZrJUbck/2Gev Scfg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XHdQsU+7; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id g29-20020a0caadd000000b0067f85f97066si123053qvb.586.2024.01.04.11.48.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 11:48:33 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XHdQsU+7; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 63166386183F for ; Thu, 4 Jan 2024 19:48:33 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by sourceware.org (Postfix) with ESMTPS id E34FF386182F for ; Thu, 4 Jan 2024 19:47:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E34FF386182F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E34FF386182F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::636 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704397664; cv=none; b=F+QwK2ZcyTYlZpl57N/3GOca7ckpFitYzGTlmZBXFruwZ+zVkAB2330JKOVZ8jFFG41W+Vpg3eXrImCHtGdFa1bUbJh+yckOBjbVIGOPSxWtMQsUHmpvotCFMcKRUJiWL2AYUkkrEKgI24pF+IWTGC8Q22+S+V3A3NN5DX2LGYY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704397664; c=relaxed/simple; bh=RVYs7rmwPjPlHi6Pi3WiTpEyjnWwBza/adBMJSLUVMA=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=dmKkVUKJuhzevaoP3cDUTf1p/bkoiMydHtZsX+hpO7p1QA3Zpmoox1CEwg1uEhqrlTV7lKA7dIrvUwxZ2yYmCohpTNOb9lJEO8DpClUOoD0r8xnVLpy6ZMOh7gRNEYr2OawtpRfa1xUehAjbPdMUn5AjQSsMUDBZL+ZYoVhuvNs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1d427518d52so5872785ad.0 for ; Thu, 04 Jan 2024 11:47:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704397658; x=1705002458; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WBgC4HIExLUhoWDbS4Q25u3oB98vuNk9TA71wKsrAkM=; b=XHdQsU+7NOjbkm1XxMgRsnFtxVYuoR3/YmdEtrVoCW5lKgKVtcHIMUrTxwvFKPIps8 5SFdCZL9/oV7Qow6PZ6MPRlwd3wbnHF46TZXqxe7RdieDoq2v60l7Qm5JEsf3ebooeZ6 HkKwZm1dn8yyuD5coiDjx+9oU6kRLGMNJgFiKg/hk1W5UV3aBVenhstZ9kMs/c2hvgZv 80yGV8wN2UagMP+b9j//OFNr/VvbuInr2P1lWc/Y+rFJlRSBmEIturWzbh4Y3U4FYp67 haqZUhc3s5np6XRrBElPBxtAeQWSVO3CLHQzpuDHa1TCTdpCP+ueAXMvRIbacwwqgzVp RxUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704397658; x=1705002458; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WBgC4HIExLUhoWDbS4Q25u3oB98vuNk9TA71wKsrAkM=; b=f9wlgSirMLH5gRnuw0NIjF49CnWAhnxTp6ubNS+7IGkq1OteNBu/HG9cuzSXTX3gda jRq5BGcmMsVo1/S2mxKQ94zBzPNPYx3HqTv9R5XAIiKgR3Nhg9lV0QwIo5s5DEfuitN9 WpJzCN6Z5/NwNd17I2vcjTD8dHcQAzdyiRfAS7bK94SOOIs+H9vnSJXr54Bk6oDeRLQR 0xgUAR1MA4r62OXeKfqree7q4biDM0cyucmIezY315OSzrb2BcFXGI45fN4f7OLqt/0f KjOVugtY8eI8PCIpc5viMJ1irh6JRSPfZColagn7LPD04Xau59VC37OIOlQEBNc+t4eC rEnw== X-Gm-Message-State: AOJu0Yz/ZlRwSbtzM0dctIUHTiH8wey9cV3n79kbX0Vqqjsnap9rUxQu KEiEnIw8kPr+OkCEoUybsZsygEkpmwnx5xyiNIz6Addb1d0= X-Received: by 2002:a17:903:4113:b0:1d3:bb4b:dc04 with SMTP id r19-20020a170903411300b001d3bb4bdc04mr994401pld.17.1704397658267; Thu, 04 Jan 2024 11:47:38 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:bd9:e135:8c7a:c648:e012]) by smtp.gmail.com with ESMTPSA id n15-20020a170902968f00b001d45fd7d444sm18868227plp.175.2024.01.04.11.47.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 11:47:37 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Joseph Myers , Florian Weimer , Jakub Jelinek Subject: [PATCH 1/2] stdlib: Fix stdbit.h with -Wconversion for older gcc Date: Thu, 4 Jan 2024 16:47:30 -0300 Message-Id: <20240104194731.2357574-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240104194731.2357574-1-adhemerval.zanella@linaro.org> References: <20240104194731.2357574-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, 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 server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patch=linaro.org@sourceware.org With gcc 6.5.0, 7.5.0, 8.5.0, and 9.5.0 the tst-stdbit-Wconversion issues the warnings: ../stdlib/stdbit.h: In function ‘__clo16_inline’: ../stdlib/stdbit.h:128:26: error: conversion to ‘uint16_t {aka short unsigned int}’ from ‘int’ may alter its value [-Werror=conversion] return __clz16_inline (~__x); ^ ../stdlib/stdbit.h: In function ‘__clo8_inline’: ../stdlib/stdbit.h:134:25: error: conversion to ‘uint8_t {aka unsigned char}’ from ‘int’ may alter its value [-Werror=conversion] return __clz8_inline (~__x); ^ ../stdlib/stdbit.h: In function ‘__cto16_inline’: ../stdlib/stdbit.h:232:26: error: conversion to ‘uint16_t {aka short unsigned int}’ from ‘int’ may alter its value [-Werror=conversion] return __ctz16_inline (~__x); ^ ../stdlib/stdbit.h: In function ‘__cto8_inline’: ../stdlib/stdbit.h:238:25: error: conversion to ‘uint8_t {aka unsigned char}’ from ‘int’ may alter its value [-Werror=conversion] return __ctz8_inline (~__x); ^ ../stdlib/stdbit.h: In function ‘__bf16_inline’: ../stdlib/stdbit.h:701:23: error: conversion to ‘uint16_t {aka short unsigned int}’ from ‘int’ may alter its value [-Werror=conversion] return __x == 0 ? 0 : ((uint16_t) 1) << (__bw16_inline (__x) - 1); ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../stdlib/stdbit.h: In function ‘__bf8_inline’: ../stdlib/stdbit.h:707:23: error: conversion to ‘uint8_t {aka unsigned char}’ from ‘int’ may alter its value [-Werror=conversion] return __x == 0 ? 0 : ((uint8_t) 1) << (__bw8_inline (__x) - 1); ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../stdlib/stdbit.h: In function ‘__bc16_inline’: ../stdlib/stdbit.h:751:59: error: conversion to ‘uint16_t {aka short unsigned int}’ from ‘int’ may alter its value [-Werror=conversion] return __x <= 1 ? 1 : ((uint16_t) 2) << (__bw16_inline (__x - 1) - 1); ^~~ ../stdlib/stdbit.h:751:23: error: conversion to ‘uint16_t {aka short unsigned int}’ from ‘int’ may alter its value [-Werror=conversion] return __x <= 1 ? 1 : ((uint16_t) 2) << (__bw16_inline (__x - 1) - 1); ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../stdlib/stdbit.h: In function ‘__bc8_inline’: ../stdlib/stdbit.h:757:57: error: conversion to ‘uint8_t {aka unsigned char}’ from ‘int’ may alter its value [-Werror=conversion] return __x <= 1 ? 1 : ((uint8_t) 2) << (__bw8_inline (__x - 1) - 1); ^~~ ../stdlib/stdbit.h:757:23: error: conversion to ‘uint8_t {aka unsigned char}’ from ‘int’ may alter its value [-Werror=conversion] return __x <= 1 ? 1 : ((uint8_t) 2) << (__bw8_inline (__x - 1) - 1); It seems to boiler down to __builtin_clz not having a variant for 8 or 16 bits. Fix it by explicit casting to the expected types. Checked on x86_64-linux-gnu and i686-linux-gnu with gcc 9.5.0. --- stdlib/stdbit.h | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/stdlib/stdbit.h b/stdlib/stdbit.h index 773b2ab72d..2945550385 100644 --- a/stdlib/stdbit.h +++ b/stdlib/stdbit.h @@ -41,6 +41,16 @@ __BEGIN_DECLS +/* Use __pacify_uint16 (N) instead of (uint16_t) (N) when the cast is helpful + only to pacify older GCC (e.g., GCC 10 -Wconversion) or non-GCC. */ +#if __GNUC_PREREQ (11, 0) +# define __pacify_uint8(n) (n) +# define __pacify_uint16(n) (n) +#else +# define __pacify_uint8(n) ((uint8_t) (n)) +# define __pacify_uint16(n) ((uint16_t) (n)) +#endif + /* Count leading zeros. */ extern unsigned int stdc_leading_zeros_uc (unsigned char __x) __THROW __attribute_const__; @@ -125,13 +135,13 @@ __clo32_inline (uint32_t __x) static __always_inline unsigned int __clo16_inline (uint16_t __x) { - return __clz16_inline (~__x); + return __clz16_inline (__pacify_uint16 (~__x)); } static __always_inline unsigned int __clo8_inline (uint8_t __x) { - return __clz8_inline (~__x); + return __clz8_inline (__pacify_uint8 (~__x)); } # define stdc_leading_ones_uc(x) (__clo8_inline (x)) @@ -229,13 +239,13 @@ __cto32_inline (uint32_t __x) static __always_inline unsigned int __cto16_inline (uint16_t __x) { - return __ctz16_inline (~__x); + return __ctz16_inline (__pacify_uint16 (~__x)); } static __always_inline unsigned int __cto8_inline (uint8_t __x) { - return __ctz8_inline (~__x); + return __ctz8_inline (__pacify_uint8 (~__x)); } # define stdc_trailing_ones_uc(x) (__cto8_inline (x)) @@ -698,13 +708,15 @@ __bf32_inline (uint32_t __x) static __always_inline uint16_t __bf16_inline (uint16_t __x) { - return __x == 0 ? 0 : ((uint16_t) 1) << (__bw16_inline (__x) - 1); + return __pacify_uint16 (__x == 0 + ? 0 : ((uint16_t) 1) << (__bw16_inline (__x) - 1)); } static __always_inline uint8_t __bf8_inline (uint8_t __x) { - return __x == 0 ? 0 : ((uint8_t) 1) << (__bw8_inline (__x) - 1); + return __pacify_uint8 (__x == 0 + ? 0 : ((uint8_t) 1) << (__bw8_inline (__x) - 1)); } # define stdc_bit_floor_uc(x) ((unsigned char) __bf8_inline (x)) @@ -748,13 +760,19 @@ __bc32_inline (uint32_t __x) static __always_inline uint16_t __bc16_inline (uint16_t __x) { - return __x <= 1 ? 1 : ((uint16_t) 2) << (__bw16_inline (__x - 1) - 1); + return (uint16_t) (__x <= 1 + ? 1 + : ((uint16_t) 2) + << (__bw16_inline ((uint16_t) (__x - 1)) - 1)); } static __always_inline uint8_t __bc8_inline (uint8_t __x) { - return __x <= 1 ? 1 : ((uint8_t) 2) << (__bw8_inline (__x - 1) - 1); + return (uint8_t) (__x <= 1 + ? 1 + : ((uint8_t) 2) + << (__bw8_inline ((uint8_t) (__x - 1)) - 1)); } # define stdc_bit_ceil_uc(x) ((unsigned char) __bc8_inline (x)) From patchwork Thu Jan 4 19:47:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 759869 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp7153141wrw; Thu, 4 Jan 2024 11:48:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IG+QCweVd1XFrJ1YO2nLTFB/cLQ+kYDnNeFsmXxno8hJjtKtfJ4m3pcbDFopliRQbPX0jcU X-Received: by 2002:a05:6214:e6d:b0:680:3f5d:8acf with SMTP id jz13-20020a0562140e6d00b006803f5d8acfmr1225801qvb.127.1704397679861; Thu, 04 Jan 2024 11:47:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704397679; cv=pass; d=google.com; s=arc-20160816; b=h3CsdgOUBbYLpskI6yFp12I1H/UNQX9fgbC5zxjFJTG4pq4OZpsARtlXP8tYKYnWPC HNK845UkubvD6Ke2yuWxYQ12mzMWP/hW/qZFPIDjJk5E9yhVX4GnDAaAQkClagQcimbx ogwrUOnh3h5JTET6ld+6cJmBy9hGOov5UmdQhpAQcldVq5jGsklyRapLrRm05u67p6Ee ClKDfN843LHMSTVUZhwRk/qBo1XYRlmDhmBjHj3Mz2NzjA1GJJrzUn1piwOwOTcipBRP ZpuX7iR9Q8qdQ8lybpXE02NmTe8d7V3Hv3pKPyoWYr19XeB0EsvHOY2kjNlsQFKnie9D yhCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=YHvwbEACa+SrdeJeui6qkZgTlUyAAwlfCIk01VU2Qvo=; fh=w4YPogs5qr06moNsiHAOaMGems29oYfgLzW3XNbqAJI=; b=vnEK4Ez+j9dlQOgQ7gjAWvmd1pQ+1q23UQ1FEsIlKIUtZjuD1MEgsLHsf5+E6nVRZ3 sgblXbNsmRevq+Mb87TO11Zm1KA3H8MQYBzdGstkLv3QNfdFxeddqdoTjX8U7sv+BzkZ tsitOu0eg1V4cA47Gq7yLRXIcgcMZ71BkTwm0M5jYCm51M0Gi8SYXE7nB4lWzO0aQNKc XyMTjTtQU+sU8f2WUW1nzABIbFqV/Fj4roFhrU5kr6/Bcj3wky/M3mLAyj+f6jfiX0gG v3Y+bSzs+Bmkp5qQHWg2sn4RU6siXYcikCOVB10gcQeTOieFOcgd1lo95T3In8p0r3xk 2c1A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="nXmU/w5g"; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id z8-20020a0cf248000000b0067f3b3dec1dsi141598qvl.258.2024.01.04.11.47.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 11:47:59 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="nXmU/w5g"; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 774DF3861010 for ; Thu, 4 Jan 2024 19:47:59 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id 03E043857830 for ; Thu, 4 Jan 2024 19:47:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 03E043857830 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 03E043857830 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704397664; cv=none; b=Wh2Bf8xcjRS7iXHunmHc88eleb0LN1eHo+ALAj4PAahzrReq6bkKrkDr5qoSqmZmAjdozQdLOqFfV0Tgtv5kKIBtDzJK1jffNW9YBxIdUMk7xYhL4TYAloHV9zOVO3Jdy35NwvV2PrSGZS1uzR1FS/QZ2PTvwW4HLlBTQJ6ganY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704397664; c=relaxed/simple; bh=ii6MSUpEKtPoQQyMaMehjU7Nt2gY7/qUt4zU8JvyH2M=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=QFYDXK9qfs9OlYudJP0lGdW5GkB0t3HxufjEUBjM8uZUIH9SI+kwEQS3Kqc5QCG9hynPB/LUET6RRWWH2mvIV95VtK9BUlhAdPRNHVui3nCDPjD0puJ1FwAwcp+883SIib+QoAJPUUzBvvaPjO5DeRsRcnjnbOHa5EVxnkYI2fw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1d3e8a51e6bso6023835ad.3 for ; Thu, 04 Jan 2024 11:47:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704397660; x=1705002460; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YHvwbEACa+SrdeJeui6qkZgTlUyAAwlfCIk01VU2Qvo=; b=nXmU/w5gNpHdtpIQCq9Z0BvGrnorBj4XGchfpWsK2Wf9+4c5Qjhhfv1Ah/7kfhzdrR UzBH/Wwsx2Y+T5rPLlnyJHO7QnOySUtnzg3V7Uwdi1EnZUy5TAia2pswPGFQqlYHc3GG 4WJoQkgBxG+rofY28BAB05XM9F/6gRY+EeVCNwY3x8BD6O7p/uEGdbmtIRuoiq5s2TRq nNV3Sn9QgyNEq51PyUSUG4puqF6QglQEKhr6GedC5C1kKhi6Z2h7SoFbpLp8TZQbERNY f2XTxwdIz/eV9Nmb5wIS3syDdDvbM3HoNmwGd/H6TKCD3FdbZUNncApX4JnnwlyThA3Q G47A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704397660; x=1705002460; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YHvwbEACa+SrdeJeui6qkZgTlUyAAwlfCIk01VU2Qvo=; b=IqWH+xpjPtXcqxe93qsWQu//N1b44a9x+nC2osN1eQtrZo1e2whhF61cqYg/YE54Yo PNKADA+Mgq4oaRzRM9oX3nMmCk1rpe+yGhytoxSc4x19pDf5yvG66BOQxLXtc1CW9SHB 9iNylmpZpC38FHYQIRG+kUtcNtv2bcbiLNURSlfAkvWRFWyg6uBOqnTK0YhW+CLWycRx T4xn72oY0fQMq1A6TFJ68Q182vcClyZdPrvcAr+ZKlzl9Bk1XSrwQTnDGWIAh0sRSgKR nR7wjfV/Oa8hyfvHsOYVoRM/tWSkOXTWXMzO+0gyXvPMxRDWpJJMx2RQliL05VpDWFHl co0Q== X-Gm-Message-State: AOJu0YzGt2SD95tk3qhI/SsuL+cu6bTiBH9XJPHXpypVJGtYluoP7fQV eQrJtIixwRqOb7CznFCx3cPIJKmdrawaqfy+EydJjveLzd4= X-Received: by 2002:a17:902:bb17:b0:1d4:e1d6:14f8 with SMTP id im23-20020a170902bb1700b001d4e1d614f8mr667756plb.75.1704397660372; Thu, 04 Jan 2024 11:47:40 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:bd9:e135:8c7a:c648:e012]) by smtp.gmail.com with ESMTPSA id n15-20020a170902968f00b001d45fd7d444sm18868227plp.175.2024.01.04.11.47.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 11:47:39 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Joseph Myers , Florian Weimer , Jakub Jelinek Subject: [PATCH 2/2] stdlib: Fix stdbit.h with -Wconversion for clang Date: Thu, 4 Jan 2024 16:47:31 -0300 Message-Id: <20240104194731.2357574-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240104194731.2357574-1-adhemerval.zanella@linaro.org> References: <20240104194731.2357574-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, 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 server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patch=linaro.org@sourceware.org With clang 14 and also with main the tst-stdbit-Wconversion issues the warnings: ../stdlib/stdbit.h:701:40: error: implicit conversion loses integer precision: 'int' to 'uint16_t' (aka 'unsigned short') [-Werror,-Wimplicit-int-conversion] return __x == 0 ? 0 : ((uint16_t) 1) << (__bw16_inline (__x) - 1); ~~~~~~ ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../stdlib/stdbit.h:707:39: error: implicit conversion loses integer precision: 'int' to 'uint8_t' (aka 'unsigned char') [-Werror,-Wimplicit-int-conversion] return __x == 0 ? 0 : ((uint8_t) 1) << (__bw8_inline (__x) - 1); ~~~~~~ ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ ../stdlib/stdbit.h:751:40: error: implicit conversion loses integer precision: 'int' to 'uint16_t' (aka 'unsigned short') [-Werror,-Wimplicit-int-conversion] return __x <= 1 ? 1 : ((uint16_t) 2) << (__bw16_inline (__x - 1) - 1); ~~~~~~ ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../stdlib/stdbit.h:757:39: error: implicit conversion loses integer precision: 'int' to 'uint8_t' (aka 'unsigned char') [-Werror,-Wimplicit-int-conversion] return __x <= 1 ? 1 : ((uint8_t) 2) << (__bw8_inline (__x - 1) - 1); ~~~~~~ ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ tst-stdbit-Wconversion.c:45:31: error: implicit conversion loses integer precision: 'unsigned short' to 'uint8_t' (aka 'unsigned char') [-Werror,-Wimplicit-int-conversion] (void) stdc_trailing_zeros (us); ~~~~~~~~~~~~~~~~~~~~~^~~ ../stdlib/stdbit.h:164:30: note: expanded from macro 'stdc_trailing_zeros' : stdc_trailing_zeros_uc (x)) ~~~~~~~~~~~~~~~~~~~~~~~~^~ ../stdlib/stdbit.h:191:52: note: expanded from macro 'stdc_trailing_zeros_uc' # define stdc_trailing_zeros_uc(x) (__ctz8_inline (x)) ~~~~~~~~~~~~~ ^ tst-stdbit-Wconversion.c:46:31: error: implicit conversion loses integer precision: 'unsigned int' to 'uint16_t' (aka 'unsigned short') [-Werror,-Wimplicit-int-conversion] (void) stdc_trailing_zeros (ui); ~~~~~~~~~~~~~~~~~~~~~^~~ ../stdlib/stdbit.h:163:48: note: expanded from macro 'stdc_trailing_zeros' : sizeof (x) == 2 ? stdc_trailing_zeros_us (x) \ ~~~~~~~~~~~~~~~~~~~~~~~~^~ ../stdlib/stdbit.h:192:53: note: expanded from macro 'stdc_trailing_zeros_us' # define stdc_trailing_zeros_us(x) (__ctz16_inline (x)) ~~~~~~~~~~~~~~ ^ tst-stdbit-Wconversion.c:46:31: error: implicit conversion loses integer precision: 'unsigned int' to 'uint8_t' (aka 'unsigned char') [-Werror,-Wimplicit-int-conversion] (void) stdc_trailing_zeros (ui); ~~~~~~~~~~~~~~~~~~~~~^~~ ../stdlib/stdbit.h:164:30: note: expanded from macro 'stdc_trailing_zeros' : stdc_trailing_zeros_uc (x)) ~~~~~~~~~~~~~~~~~~~~~~~~^~ ../stdlib/stdbit.h:191:52: note: expanded from macro 'stdc_trailing_zeros_uc' # define stdc_trailing_zeros_uc(x) (__ctz8_inline (x)) ~~~~~~~~~~~~~ ^ tst-stdbit-Wconversion.c:47:31: error: implicit conversion loses integer precision: 'unsigned long' to 'uint16_t' (aka 'unsigned short') [-Werror,-Wimplicit-int-conversion] (void) stdc_trailing_zeros (ul); ~~~~~~~~~~~~~~~~~~~~~^~~ ../stdlib/stdbit.h:163:48: note: expanded from macro 'stdc_trailing_zeros' : sizeof (x) == 2 ? stdc_trailing_zeros_us (x) \ ~~~~~~~~~~~~~~~~~~~~~~~~^~ ../stdlib/stdbit.h:192:53: note: expanded from macro 'stdc_trailing_zeros_us' # define stdc_trailing_zeros_us(x) (__ctz16_inline (x)) ~~~~~~~~~~~~~~ ^ [...] It seems to boiler down to __builtin_clz not having a variant for 8 or 16 bits. Fix it by explicit casting to the expected types. Although not strickly required for older gcc, using the same __pacify macro simpify the required code. Checked on x86_64-linux-gnu and i686-linux-gnu. --- stdlib/stdbit.h | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/stdlib/stdbit.h b/stdlib/stdbit.h index 2945550385..9daf414651 100644 --- a/stdlib/stdbit.h +++ b/stdlib/stdbit.h @@ -42,7 +42,8 @@ __BEGIN_DECLS /* Use __pacify_uint16 (N) instead of (uint16_t) (N) when the cast is helpful - only to pacify older GCC (e.g., GCC 10 -Wconversion) or non-GCC. */ + only to pacify older GCC (e.g., GCC 10 -Wconversion) or non-GCC (e.g + clang -Wimplicit-int-conversion). */ #if __GNUC_PREREQ (11, 0) # define __pacify_uint8(n) (n) # define __pacify_uint16(n) (n) @@ -198,8 +199,8 @@ __ctz8_inline (uint8_t __x) return __x == 0 ? 8U : (unsigned int) __builtin_ctz (__x); } -# define stdc_trailing_zeros_uc(x) (__ctz8_inline (x)) -# define stdc_trailing_zeros_us(x) (__ctz16_inline (x)) +# define stdc_trailing_zeros_uc(x) (__ctz8_inline (__pacify_uint8 (x))) +# define stdc_trailing_zeros_us(x) (__ctz16_inline (__pacify_uint16 (x))) # define stdc_trailing_zeros_ui(x) (__ctz32_inline (x)) # if __WORDSIZE == 64 # define stdc_trailing_zeros_ul(x) (__ctz64_inline (x)) @@ -302,8 +303,8 @@ __flz8_inline (uint8_t __x) return __x == (uint8_t) -1 ? 0 : 1 + __clo8_inline (__x); } -# define stdc_first_leading_zero_uc(x) (__flz8_inline (x)) -# define stdc_first_leading_zero_us(x) (__flz16_inline (x)) +# define stdc_first_leading_zero_uc(x) (__flz8_inline (__pacify_uint8 (x))) +# define stdc_first_leading_zero_us(x) (__flz16_inline (__pacify_uint16 (x))) # define stdc_first_leading_zero_ui(x) (__flz32_inline (x)) # if __WORDSIZE == 64 # define stdc_first_leading_zero_ul(x) (__flz64_inline (x)) @@ -356,8 +357,8 @@ __flo8_inline (uint8_t __x) return __x == 0 ? 0 : 1 + __clz8_inline (__x); } -# define stdc_first_leading_one_uc(x) (__flo8_inline (x)) -# define stdc_first_leading_one_us(x) (__flo16_inline (x)) +# define stdc_first_leading_one_uc(x) (__flo8_inline (__pacify_uint8 (x))) +# define stdc_first_leading_one_us(x) (__flo16_inline (__pacify_uint16 (x))) # define stdc_first_leading_one_ui(x) (__flo32_inline (x)) # if __WORDSIZE == 64 # define stdc_first_leading_one_ul(x) (__flo64_inline (x)) @@ -410,8 +411,8 @@ __ftz8_inline (uint8_t __x) return __x == (uint8_t) -1 ? 0 : 1 + __cto8_inline (__x); } -# define stdc_first_trailing_zero_uc(x) (__ftz8_inline (x)) -# define stdc_first_trailing_zero_us(x) (__ftz16_inline (x)) +# define stdc_first_trailing_zero_uc(x) (__ftz8_inline (__pacify_uint8 (x))) +# define stdc_first_trailing_zero_us(x) (__ftz16_inline (__pacify_uint16 (x))) # define stdc_first_trailing_zero_ui(x) (__ftz32_inline (x)) # if __WORDSIZE == 64 # define stdc_first_trailing_zero_ul(x) (__ftz64_inline (x)) @@ -464,8 +465,8 @@ __fto8_inline (uint8_t __x) return __x == 0 ? 0 : 1 + __ctz8_inline (__x); } -# define stdc_first_trailing_one_uc(x) (__fto8_inline (x)) -# define stdc_first_trailing_one_us(x) (__fto16_inline (x)) +# define stdc_first_trailing_one_uc(x) (__fto8_inline (__pacify_uint8 (x))) +# define stdc_first_trailing_one_us(x) (__fto16_inline (__pacify_uint16 (x))) # define stdc_first_trailing_one_ui(x) (__fto32_inline (x)) # if __WORDSIZE == 64 # define stdc_first_trailing_one_ul(x) (__fto64_inline (x))