From: Jakub Jelinek <jakub@redhat.com>
To: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Cc: Joseph Myers <jsm@polyomino.org.uk>,
Florian Weimer <fweimer@redhat.com>,
libc-alpha@sourceware.org
Subject: Re: [PATCHv2] Implement C23 <stdbit.h>
Date: Thu, 4 Jan 2024 17:49:15 +0100 [thread overview]
Message-ID: <ZZbhiwU6ZqEWMFx1@tucnak> (raw)
In-Reply-To: <5869249a-634d-47b2-a351-adc5f63ce087@linaro.org>
On Thu, Jan 04, 2024 at 01:34:36PM -0300, Adhemerval Zanella Netto wrote:
> It seems the current macros does not work flawlessly with old gcc versions
> or with clang. With gcc 6.5.0, 7.5.0, 8.5.0, and 9.5.0 I see:
>
> ../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);
> ^
Guess if the header needs to be -Wconversion warning free (or
-Wconversion -Wsystem-headers even), one could use
return __clz16_inline ((uint16_t) ~x);
etc.
> ../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);
> ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
or
return (uint16_t) (__x == 0 ? 0 : ((uint16_t) 1) << (__bw16_inline (__x) - 1));
Of course only for the spots where warnings occur, so uint8_t/uint16_t
related ops that promote to int and are right now explicitly converted back
to those narrower types.
Jakub
next prev parent reply other threads:[~2024-01-04 16:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-02 15:12 Joseph Myers
2024-01-03 9:58 ` Florian Weimer
2024-01-04 16:34 ` Adhemerval Zanella Netto
2024-01-04 16:49 ` Jakub Jelinek [this message]
2024-01-04 17:09 ` Adhemerval Zanella Netto
2024-01-04 17:42 ` Paul Eggert
2024-01-04 18:50 ` Adhemerval Zanella Netto
2024-01-22 18:02 ` Joseph Myers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZZbhiwU6ZqEWMFx1@tucnak \
--to=jakub@redhat.com \
--cc=adhemerval.zanella@linaro.org \
--cc=fweimer@redhat.com \
--cc=jsm@polyomino.org.uk \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).