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: 83334 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B89923861838 for ; Thu, 4 Jan 2024 19:48:44 +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-Google-Smtp-Source: AGHT+IEz0W8l5zivReRl44Xcbr45ZeV5xfIBcq+sP8I3o22MnczBdh7gamoBbrt9Ix6pN8OolmtM7g== 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+patchwork=sourceware.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: 83333 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C36C63861810 for ; Thu, 4 Jan 2024 19:48:12 +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-Google-Smtp-Source: AGHT+IGvupojv+pHnGXry5T5Jkv4URQVgRQIzlybCv9LNp7c/j6jP74Lx91+ieSBsDihM9aJzdyKIQ== 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+patchwork=sourceware.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))