This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/15512] New: __bswap_constant_16 not compiled when -Werror -Wsign-conversion is given
- From: "edjee at google dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Tue, 21 May 2013 18:56:46 +0000
- Subject: [Bug libc/15512] New: __bswap_constant_16 not compiled when -Werror -Wsign-conversion is given
- Auto-submitted: auto-generated
http://sourceware.org/bugzilla/show_bug.cgi?id=15512
Bug #: 15512
Summary: __bswap_constant_16 not compiled when -Werror
-Wsign-conversion is given
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: unassigned@sourceware.org
ReportedBy: edjee@google.com
CC: drepper.fsp@gmail.com
Classification: Unclassified
(Filling a bug, following Andreas' suggestion)
I'm using gcc and glibc on 32bit LE ARM (But all the other platforms that use
the architecture-independent bit/byteswap.h may have similar issue).
I found that the following code is not compiled, if I give -Werror
-Wsign-conversion arguments to gcc.
#include <stdio.h>
#include <byteswap.h>
int main(int argc, char *argv[]) {
unsigned short int x = 0xbeef;
printf("bswap_16(0x%x)=0x%x\n", x, bswap_16(x));
return 0;
}
I saw compilation error "conversion to 'unsigned int' from 'int' may change the
sign of the result".
It looks like that a similar issue has been solved for x86 by
http://sourceware.org/git/?p=glibc.git;a=commit;h=69da074d7adfab7b57004a0dea9403a928e310a5
.
But the architecture-independent bit/byteswap.h has not been modified. In that
file, __bswap_constant_16 macro looks like this:
#define __bswap_constant_16(x) \
((unsigned short int)((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8)))
It seems that ((x) >> 8) promotes the data to signed value, even if x is
unsigned. So (((x) >> 8) && 0xffu) seems to fail when -Werror -Wsign-conversion
is given.
All the architecture-specific versions of byteswap.h uses 0xff but this file
uses 0xffu. Is this intended?
--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.