From patchwork Fri Jan 5 17:17:41 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: 760233 Delivered-To: patch@linaro.org Received: by 2002:a5d:678d:0:b0:336:6142:bf13 with SMTP id v13csp150747wru; Fri, 5 Jan 2024 09:18:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IFJF+5T495PLB2b0Khr+rSQMRspU7ZzIYlPdLe2syxF4F1Dtj9Ub09oREY+ylCZDVtFmkP1 X-Received: by 2002:a05:6808:20a5:b0:3bc:3c8f:6040 with SMTP id s37-20020a05680820a500b003bc3c8f6040mr399416oiw.89.1704475086024; Fri, 05 Jan 2024 09:18:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704475085; cv=pass; d=google.com; s=arc-20160816; b=Wnwh8JO8kwH+GZgJtbPixfA4GBMRlmm+seyFE2upPWLFz60Zipc0pfYjugLZgT5qc0 atKr4PeMNrI01d4WEaQZkU10bBhx1WCZTiH3XzW8hbqYqWvXY1I9l/Rfe4yN2lgrOB2h CXoeA9cEYYXWSK2XIokndwI9DKYztzIewNkcUJh4KWgNNbYk6Unnb4+jQNi/of07FoEw B81xTj4Z2355Zm0WzPkARxoIlPHR9wPdQexFn03jxbBRz98tB2VpLGmXH595gRJSS0sk ceaSghsvPG63tIMAYeryeu0P7zrCbF0KsZ2BNZVETsOd2xxpw+6Wo9nx07LwjAiFXzaV pq8A== 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=LrRL5UCih8YCASIGl3X0i92yHcFyKPvrL0pLSWDBsPQ=; fh=kLd2VK3ZPWVSXVZQyPztCBrluAdcsGzLxepxFWofaZM=; b=ZteA2lr0POYDi8yGfTNiJjI9LepcrUxANIzEDyxWWVwAmwkhcpId1eN9svxjoG+RFv 75n/mJjhQDRtOJlhuM37hBRmUx+OVoxicuYRKCGutIpiukhVhB66Efgp2qgSzcEneeIf zCUH98LcZWrxzQrh9CO1iJB/GKKt+JtHaUmlKWzaynmV/bT71jsPlEa7BsB07HxxDE7d bA6AAcABoEtvQTuA7tDll5c/1+/BjcINj3YRFy+DI4+/LYeOaEhx6YVkKJPxxDZGajCD LVUk70VM3qUkK1Lb6417cSPrWmTtytAzF1ZYSRxiL9SMFZl/ZDA7VRc17oNmOaSH6GZC D7Yw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C4qqbhcu; 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 e10-20020a0562141d0a00b0067f31950499si1213554qvd.276.2024.01.05.09.18.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 09:18:05 -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=C4qqbhcu; 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 9EFF0385C6F7 for ; Fri, 5 Jan 2024 17:18:05 +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 50A183858284 for ; Fri, 5 Jan 2024 17:17:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 50A183858284 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 50A183858284 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=1704475072; cv=none; b=IqVDseU2E7wd14J2OpNh2gNTZiqf3zlP2JqNQqJjRFsfwgQPP5IeuNHrS6tU1oSCyGeIcd7Upq/QNFTYr4gYeY35oS3k+1OQnXi+JmdZrhODd9jMh0zoqvOlJrVhYI1UBVTimFS9m3AXXfctOfDAJWMYMZVdaRCwFv5NAbHS5Do= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704475072; c=relaxed/simple; bh=pqs9YWEug7AVlwWcgOvriEzcWRL8ZZbX6ES9jsQRYr8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=QLwzZheAi1euldx6xKsb/65ns9F1ifA0tMkNn9nXpI0xeYsagSgs5sOgJAudH7TnK1L/jlHGeLn3iyYH92ZeU9/gN1vpGDtQ4zjwHaLlj6iGz+izNkzi4uPDQStYX1QsohGawgZYNOWwyYy24nrdWZUSXrECPCCxWQO2a0b7Q7k= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1d4df66529bso10466075ad.1 for ; Fri, 05 Jan 2024 09:17:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704475069; x=1705079869; 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=LrRL5UCih8YCASIGl3X0i92yHcFyKPvrL0pLSWDBsPQ=; b=C4qqbhculyjrUQPAJwJ9Dg+fK8x844vvL8Vp2+v8NsRlbYURlkhFFd7vEmvD0Gl8yL hMtyuo6ofTNtfy8dqKN0q1UYji2+b4rJb6Z1dkG4rlKrMD0g22H1gYRlQAw+PEoyIUah zz3S0TORNLF5m4ub51uUa/Y/BWk5ej3suIlq7hBfWnQ5G2VLVIzIwRQ1jK0afJL428Du YNi6JRqEcct72vGbqvlfl+a1/o3QxtjBKrjNGSOVY3dVVrVxg47bW6BGmzhRIX+Gy3Rx tqlqOzJHfpJJ2YVDtZQeb1Sdk7M4Gt4fMnHReZzwwxn1VpFwho5mv+QPhy/5jqMEGEx+ UfTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704475069; x=1705079869; 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=LrRL5UCih8YCASIGl3X0i92yHcFyKPvrL0pLSWDBsPQ=; b=iDT7y/hFsKawcSqvo2qOlokC15Gupi6e+VwFCmFsGu6/ummq7SGoawJlctUMdTTLCm HKDYGyOXIViuP2LPBR+r9vZtVt2gifeTUIX0JinEVAkmVUKLYP/kZzoXKP5eF8IG8WK8 4/ZwrtYjTHcYXUFl3+khV4NvQOxWbplCJyK/fG2o+ah7rJNJfp6grT2ChraNTOGDSQRR EgXXhTT67bjS2g9F/8wyaRubHpJdfCIzLqz27H4nNrENbFVE0coZxANr0+Y5LRHtUAvm e7Bo5OUIhdj5KjOSfL7ZykspkF1MonZfs7dvin+nii8IdNZbQgN2WCoQrR+JopGiYuwQ k6Rw== X-Gm-Message-State: AOJu0YwhlT5tiMjqhtkuX+QeYIjN/x56JRGMLfYWDBtDXqgwvhqwtU05 EsiND9boxGfZSG9xX/0SYcHtlE7nEVfgP68JTrEu4IW7a9A= X-Received: by 2002:a17:903:124a:b0:1d3:c228:9545 with SMTP id u10-20020a170903124a00b001d3c2289545mr2335447plh.5.1704475068847; Fri, 05 Jan 2024 09:17:48 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:9dd2:6f94:a8f0:eddb:341]) by smtp.gmail.com with ESMTPSA id d15-20020a170902b70f00b001d4974385d4sm1630483pls.250.2024.01.05.09.17.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 09:17:48 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Joseph Myers Subject: [PATCH 2/2] stdlib: Fix stdbit.h with -Wconversion for clang Date: Fri, 5 Jan 2024 14:17:41 -0300 Message-Id: <20240105171741.1919436-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240105171741.1919436-1-adhemerval.zanella@linaro.org> References: <20240105171741.1919436-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 61165dd725..f334eb174d 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) @@ -170,8 +171,8 @@ extern unsigned int stdc_trailing_zeros_ull (unsigned long long int __x) #define stdc_trailing_zeros(x) \ (sizeof (x) == 8 ? stdc_trailing_zeros_ull (x) \ : sizeof (x) == 4 ? stdc_trailing_zeros_ui (x) \ - : sizeof (x) == 2 ? stdc_trailing_zeros_us (x) \ - : stdc_trailing_zeros_uc (x)) + : sizeof (x) == 2 ? stdc_trailing_zeros_us (__pacify_uint16 (x)) \ + : stdc_trailing_zeros_uc (__pacify_uint8 (x))) #if __GNUC_PREREQ (3, 4) || __glibc_has_builtin (__builtin_ctzll) static __always_inline unsigned int @@ -274,8 +275,8 @@ extern unsigned int stdc_first_leading_zero_ull (unsigned long long int __x) #define stdc_first_leading_zero(x) \ (sizeof (x) == 8 ? stdc_first_leading_zero_ull (x) \ : sizeof (x) == 4 ? stdc_first_leading_zero_ui (x) \ - : sizeof (x) == 2 ? stdc_first_leading_zero_us (x) \ - : stdc_first_leading_zero_uc (x)) + : sizeof (x) == 2 ? stdc_first_leading_zero_us (__pacify_uint16 (x)) \ + : stdc_first_leading_zero_uc (__pacify_uint8 (x))) #if __GNUC_PREREQ (3, 4) || __glibc_has_builtin (__builtin_clzll) static __always_inline unsigned int @@ -328,8 +329,8 @@ extern unsigned int stdc_first_leading_one_ull (unsigned long long int __x) #define stdc_first_leading_one(x) \ (sizeof (x) == 8 ? stdc_first_leading_one_ull (x) \ : sizeof (x) == 4 ? stdc_first_leading_one_ui (x) \ - : sizeof (x) == 2 ? stdc_first_leading_one_us (x) \ - : stdc_first_leading_one_uc (x)) + : sizeof (x) == 2 ? stdc_first_leading_one_us (__pacify_uint16 (x)) \ + : stdc_first_leading_one_uc (__pacify_uint8 (x))) #if __GNUC_PREREQ (3, 4) || __glibc_has_builtin (__builtin_clzll) static __always_inline unsigned int @@ -382,8 +383,8 @@ extern unsigned int stdc_first_trailing_zero_ull (unsigned long long int __x) #define stdc_first_trailing_zero(x) \ (sizeof (x) == 8 ? stdc_first_trailing_zero_ull (x) \ : sizeof (x) == 4 ? stdc_first_trailing_zero_ui (x) \ - : sizeof (x) == 2 ? stdc_first_trailing_zero_us (x) \ - : stdc_first_trailing_zero_uc (x)) + : sizeof (x) == 2 ? stdc_first_trailing_zero_us (__pacify_uint16 (x)) \ + : stdc_first_trailing_zero_uc (__pacify_uint8 (x))) #if __GNUC_PREREQ (3, 4) || __glibc_has_builtin (__builtin_ctzll) static __always_inline unsigned int @@ -436,8 +437,8 @@ extern unsigned int stdc_first_trailing_one_ull (unsigned long long int __x) #define stdc_first_trailing_one(x) \ (sizeof (x) == 8 ? stdc_first_trailing_one_ull (x) \ : sizeof (x) == 4 ? stdc_first_trailing_one_ui (x) \ - : sizeof (x) == 2 ? stdc_first_trailing_one_us (x) \ - : stdc_first_trailing_one_uc (x)) + : sizeof (x) == 2 ? stdc_first_trailing_one_us (__pacify_uint16 (x)) \ + : stdc_first_trailing_one_uc (__pacify_uint8 (x))) #if __GNUC_PREREQ (3, 4) || __glibc_has_builtin (__builtin_ctzll) static __always_inline unsigned int