From patchwork Fri Jan 5 17:17:40 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: 1883078 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=itRCBmYM; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T69CB53dQz1yP3 for ; Sat, 6 Jan 2024 04:18:14 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A6F60385DC37 for ; Fri, 5 Jan 2024 17:18:12 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id A4BF33858C98 for ; Fri, 5 Jan 2024 17:17:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A4BF33858C98 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 A4BF33858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::634 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704475071; cv=none; b=CgqfikbvkKrcmIwRhf+XmdhFR7O0l1paHROwAoYrWTTWFeL54yL2sRc3hg+74r3e8ainhk0ynJ9zDpts+7ybRyB1vFFzl3wOdO2k/KrlZzeXwAGNcOGB4DAWISbXDtAES3Ft5dKb60Igwhj2fMabzKTVdLi7ffjSITJ7ae3QhDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704475071; c=relaxed/simple; bh=3uNWAKIQARahOi77mpIUvNgX+P9LJy0j1lTjJH2MeZw=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=qv2CzkaWOe7M+lgowON+WUv2m0Pw16bFdz6kj0OY4EX7W4dpso9fKbVwG4iUKBzCdlyahPEpvTZTiUxcvG4DAiAVrmKNocIqKfsaH5KDxknW81T1UvM6O7LSf1BAGNMcGvI58+2a//0NGnoK4Ba3HKCNX1vGyCd+QuUKDqdguD4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1d4ba539f6cso13379005ad.3 for ; Fri, 05 Jan 2024 09:17:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704475067; x=1705079867; 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=ThysoxLMTjBXH3nu22gRwYTDjpi0qwKIp3mgLnpOAgg=; b=itRCBmYMFZvK7m1Soci7WeK4pja+swpsQP4T2UEsVMEF5TSOm9xOdVA4MAw6ceTOeW d5nIuIGw4r6//Z5pyXKGIkmSCNB7wcRGE/FuCin5NK7s+DwW5NBR6AGnFIll8ernFPUx SrLhZEgcMah3JxQhiKvaN/yD5/6JbATJI1WF5+un3bawtVmdvABEIw1bpSTKzZylphXv QW3+wOQNV/ccbo5c9EiVsNolp5qT98/Bw6vkAXdMkp+7I7oD30UxUXRqq2zvgqZ1Uz/X Y02d0B4QJuXJaLQxBRjIK6IP1VZ1OWPdLWRRV857YAhIDPEH2y9ukWW3pJF8/sDpm130 ZGag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704475067; x=1705079867; 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=ThysoxLMTjBXH3nu22gRwYTDjpi0qwKIp3mgLnpOAgg=; b=ThUgWxPbAR2fT7rMlKsyPWFX4JyUJOf3Y/tg4ULOxdHlJ2aO3uqUWbzhbIcHP2tPp2 uEXLqQzyU9XrA6Bjhb2DHy81Uzr8fp8v8y19FTPwU+nvIDa79DjYx2q3b5woLTmFs3KH rSZIB80SxvuioztDOu5v2N8IZeCfG2edDxLyWvhxKal27DqU2QQGd82WMorWzEt5VXVq +UG3jYX/JPHIhHfGoG8n/HUBON/gNm6MrRGXGaKmBC+JKd4Qw/mS26it4XErbH7u6E9w bASfQEtqScsPF4FN52fTPZwfMi7lZ7rE0IDE/ZDW7trNTjYWF2KfKj7PIkKuUDcOFfCo BmfQ== X-Gm-Message-State: AOJu0YzjyVJAI8Sw2RS/4UETGXGoMA4pzlbRnC6SCL6I+/C2QABBYvB9 TjbQrYLqrI+8HXFvK1Fw8yIs7xRsQIdbFbj1xqhdQmD5wb0= X-Google-Smtp-Source: AGHT+IGT9kBjSmX5IOwmuacfTOeepv769Adw6lOh5xh2GRSwXHMGA4F0SO2T4vKzX+t2MvC0/ITgZg== X-Received: by 2002:a17:903:124b:b0:1d4:691e:817f with SMTP id u11-20020a170903124b00b001d4691e817fmr2135384plh.126.1704475067142; Fri, 05 Jan 2024 09:17:47 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 09:17:46 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Joseph Myers Subject: [PATCH 1/2] stdlib: Fix stdbit.h with -Wconversion for older gcc Date: Fri, 5 Jan 2024 14:17:40 -0300 Message-Id: <20240105171741.1919436-2-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+incoming=patchwork.ozlabs.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..61165dd725 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 __pacify_uint16 (__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 __pacify_uint8 (__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 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: 1883079 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=C4qqbhcu; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T69CC5tdFz1yP3 for ; Sat, 6 Jan 2024 04:18:15 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ADD50385DC0C for ; Fri, 5 Jan 2024 17:18:13 +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-Google-Smtp-Source: AGHT+IEEiGy5RujGFbK1ulYjdiP0xYugyQJuCQW7PqA7JDaRs+gO6fkbue/kYuaC+rhtCDmUzVda2w== 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+incoming=patchwork.ozlabs.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