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))