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 X-Patchwork-Id: 760232 Delivered-To: patch@linaro.org Received: by 2002:a5d:678d:0:b0:336:6142:bf13 with SMTP id v13csp150735wru; Fri, 5 Jan 2024 09:18:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IGYKt3DPoBm7iXdj5GXqVZ+nuOa8Uuo6JeyLkCCZqGXsMuKCu8vsJyErFLt/Yd5JUG1yE5x X-Received: by 2002:a05:620a:45aa:b0:781:5611:caa0 with SMTP id bp42-20020a05620a45aa00b007815611caa0mr2727453qkb.29.1704475084779; Fri, 05 Jan 2024 09:18:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704475084; cv=pass; d=google.com; s=arc-20160816; b=BQbrYuYvBwM7uOmnysJYTheN88JK0LvKsCnnfY9hLnDeeFNOORLvdnJZ20erSfsQ9t NuvogRnIlCfLedl4z5REIMdM2m40Z06zc9FH2GXyydndJkDQ2fyXtCRLF0qlNCNzeH6n D+bfFUzH+vOOIfVl8ttv0Ab8X1AScbFaoTKEQ04k4chGxzBy78UBygKATez5rYf7N0X2 5um1gEKcjTb7I+FcXgMz+1Nmx3SB9MLEqoBMMIu1a3LQd0b0EhHFsYnbzLwyfi/uUJpW A05tXIKSw5jBbL5EVKs+70p84UZtfEd2kbhHLBiDBdmph7xX9DpTNkv3W/yKB1Xri4+Y SKfg== 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=ThysoxLMTjBXH3nu22gRwYTDjpi0qwKIp3mgLnpOAgg=; fh=kLd2VK3ZPWVSXVZQyPztCBrluAdcsGzLxepxFWofaZM=; b=gmoK95Vef/Xo3N0HG0EOb/T5FV6qG515zW7QKY4JshfUSvoGAl24x5fBPN4iJQ56DD H8Gx1c2Uh8I9x+WYX8RIac6vC8oxikEmUGaiYy/pWTVd15PasvlkMOx7GRMS1roUzmia 5twTGxxelxLfulq1Cc+D2x+HJZV+vrfBXKPQr40nIA14ipNoUFtTMUugc/0YTxCJLExh YWWdhQ8K+R4FBdtgM6vqsRG1XN/OWJNgZWBgOjEgdCVb2OdDH9H64pu9AgHtarxYZq9m LUzmB8DT71jH6AxAToLfqAP3cqBiDx5335o6nAgjsWtyS1gXH9ksYbIaGEwllEF5WiIJ v7xA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=itRCBmYM; 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 bl20-20020a05620a1a9400b007830941fed0si1675175qkb.722.2024.01.05.09.18.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 09:18:04 -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=itRCBmYM; 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 61D2C385DC28 for ; Fri, 5 Jan 2024 17:18:04 +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-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+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..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))