[PR38370] inconsistent warnings when comparing uint8_t vs. unsigned char
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
gcc |
Invalid
|
Low
|
|||
gcc-4.3 (Ubuntu) |
Triaged
|
Low
|
Unassigned |
Bug Description
Binary package hint: gcc-4.3
When I compile a small test program, the compiler shows a warning I would either not expect at all, or expect it to appear for all four if-statements used in my example:
$ gcc -Wextra -c promotion.c
promotion.c: In function ‘main’:
promotion.c:10: warning: comparison of promoted ~unsigned with unsigned
$ gcc --version
gcc (Ubuntu 4.3.2-1ubuntu11) 4.3.2
$ uname -a
Linux foobar 2.6.27-7-generic #1 SMP Fri Oct 24 06:40:41 UTC 2008 x86_64 GNU/Linux
promotion.c:
typedef unsigned char uint8_t;
int main(void)
{
uint8_t a = 0;
uint8_t b = 0;
unsigned char c = 0;
unsigned char d = 0;
if (a == (b ^ 0xff)) { }
if (a == (d ^ 0xff)) { }
if (c == (b ^ 0xff)) { }
if (c == (d ^ 0xff)) { }
return 0;
}
Changed in gcc-4.3: | |
importance: | Undecided → Low |
status: | New → Triaged |
Changed in gcc: | |
status: | Unknown → New |
Changed in gcc: | |
status: | New → Invalid |
Changed in gcc: | |
status: | Invalid → Unknown |
Changed in gcc: | |
status: | Unknown → New |
Changed in gcc: | |
importance: | Unknown → Low |
Changed in gcc: | |
status: | New → Confirmed |
Changed in gcc: | |
status: | Confirmed → Invalid |
Compiler gives wrong warning for "comparison of promoted ~unsigned with unsigned" when compiling with ARM-ELF.
Submit script for building arm-elf toolchain and testcode.
Compilation using;
arm-elf-gcc -c cast.c -W
cast.c: In function 'test_cast':
cast.c:13: warning: comparison of promoted ~unsigned with unsigned
Best Regards
Fredrik Hederstierna
============
FILE: cast.c
============
typedef unsigned char u8_t;
void test_cast(void) {
unsigned char c1 = 0;
unsigned char c2 = 0;
u8_t u1 = 0;
u8_t u2 = 0;
if (c1 == (unsigned char)(~c2)) {
}
if (u1 == (u8_t)(~u2)) { // THIS WILL GIVE WARNING
}
}
======= ======= ======= === ======= ======= ===
FILE: build_toolchain.sh
=======
set -e -x
TARGET=arm-elf
BINUTILS_ VERSION= 2.19 VERSION= 1.16.0
GCC_VERSION=4.3.2
NEWLIB_
GDB_VERSION=6.8
INSIGHT_VERSION=6.8
DEST="/ usr/local/ gcc/arm- elf-tools- $GCC_VERSION"
BINUTILS_ DIR="binutils- $BINUTILS_ VERSION" "gcc-$GCC_ VERSION" DIR="newlib- $NEWLIB_ VERSION" "gdb-$GDB_ VERSION" DIR="insight- $INSIGHT_ VERSION"
GCC_DIR=
NEWLIB_
GDB_DIR=
INSIGHT_
# set rwx access
umask 022
# unpack tar-balls
rm -fr "$BINUTILS_DIR" "$GCC_DIR" "$NEWLIB_DIR" "$GDB_DIR" "$INSIGHT_DIR" $BINUTILS_ VERSION. tar.bz2" VERSION. tar.bz2" $NEWLIB_ VERSION. tar.gz" VERSION. tar.bz2" $INSIGHT_ VERSION. tar.bz2"
tar xvjf "binutils-
tar xvjf "gcc-$GCC_
tar xvzf "newlib-
tar xvjf "gdb-$GDB_
tar xvjf "insight-
cd "$GCC_DIR" DIR/newlib" newlib DIR/libgloss" libgloss
ln -s "../$NEWLIB_
ln -s "../$NEWLIB_
cd ..
rm -fr build
mkdir -p build/binutils build/gcc build/gdb build/insight build/newlib
# Build binutils
cd build/binutils $BINUTILS_ DIR/configure" --target="$TARGET" --prefix="$DEST" --disable-nls
"../../
make LDFLAGS=-s all install
# Build GCC
cd ../gcc DEST/bin: $PATH" $GCC_DIR/ configure" --enable- languages= c,c++ --target="$TARGET" --prefix="$DEST" --with-gnu-as --with-gnu-ld --disable-nls --with-newlib --disable- __cxa_atexit --with-ecos libstdc+ +-v3 install install-gcc install- target- libstdc+ +-v3
PATH="$
"../../
make LDFLAGS=-s all all-gcc all-target-
# Build GDB and Insight
cd ../gdb $GDB_DIR/ configure" --target="$TARGET" --prefix="$DEST"
# Without insight
"../../
make -w all install
cd ../insight $INSIGHT_ DIR/configure" --target="$TARGET" --prefix="$DEST"
# With insight
"../../
make -w all install
# Remove uncompressed sources
cd ../..
rm -fr "$BINUTILS_DIR" "$GCC_DIR" "$NEWLIB_DIR" "$GDB_DIR" "$INSIGHT_DIR" build