[Bug c/69828] New: result of shift operation has wrong type
tom239 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon Feb 15 19:47:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69828
Bug ID: 69828
Summary: result of shift operation has wrong type
Product: gcc
Version: 4.8.4
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: tom239 at gmail dot com
Target Milestone: ---
The result of a shift operation should have the type of the left operand.
That is not the case in a testcase below; the result of the third shift should
have a signed type and thus should be sign-extended before assignment to x32_c.
gcc -v returns:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
4.8.4-2ubuntu1~14.04.1' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs
--enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.8 --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls
--with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap
--enable-plugin --with-system-zlib --disable-browser-plugin
--enable-java-awt=gtk --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.1)
seen under Ubuntu 14.04.3 LTS. uname -a returns:
Linux croce 3.13.0-77-generic #121-Ubuntu SMP Wed Jan 20 10:50:42 UTC 2016
x86_64 x86_64 x86_64 GNU/Linux
sample compilation and execution:
> gcc signbug.c ; a.out
should be negative: -32768
should be negative: -32768
should be negative: 32768
complete testcase code (.i output from gcc -save-temps):
# 1 "signbug.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "signbug.c"
extern int printf (const char *__restrict __format, ...);
typedef signed char i8_t;
typedef unsigned char u8_t;
typedef signed short int i16_t;
typedef signed int i32_t;
int main(int argc,const char** argv)
{
i8_t i = (argc < 0) | 0x80;
u8_t u = i;
i16_t x16 = ((i16_t)u) << 8;
i32_t x32_a = x16;
i32_t x32_b = ((i16_t)i) << 8;
i32_t x32_c = ((i16_t)u) << 8;
printf("should be negative: %7d\n",x32_a);
printf("should be negative: %7d\n",x32_b);
printf("should be negative: %7d\n",x32_c);
return 0;
}
More information about the Gcc-bugs
mailing list