https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116063
Bug ID: 116063
Summary: [PPC] Transparent union issue with signedness when
optimizing
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: hstong at ca dot ibm.com
Target Milestone: ---
Target: powerpc64le-unknown-linux-gnu
When generating optimized code for a powerpc64le Linux target (and also 32-bit
and 64-bit AIX), GCC miscompiles accesses to signed members of transparent
union parameters having unsigned first members.
In particular, the necessary sign extension is not performed.
### SOURCE (<stdin>):
typedef union __attribute__((__transparent_union__)) U {
unsigned char u;
signed char x;
} U;
__attribute__((__weak__))
long f(U u) { return u.x; }
signed char x = -1;
int printf(const char *, ...);
int main(void) {
printf("%ld\n", f(x));
}
### COMPILER INVOCATION:
gcc -O -o a.out -xc -
### RUN COMMAND:
./a.out
### ACTUAL OUTPUT (stdout):
255
### EXPECTED OUTPUT (stdout):
-1
### COMPILER VERSION INFO (gcc -v):
Using built-in specs.
COLLECT_GCC=/opt/compiler-explorer/powerpc64le/gcc-trunk/powerpc64le-unknown-linux-gnu/bin/powerpc64le-unknown-linux-gnu-gcc
Target: powerpc64le-unknown-linux-gnu
Configured with: /opt/.build/powerpc64le-unknown-linux-gnu/src/gcc/configure
--build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu
--target=powerpc64le-unknown-linux-gnu
--prefix=/opt/compiler-explorer/powerpc64le/gcc-trunk-20240723/powerpc64le-unknown-linux-gnu
--exec_prefix=/opt/compiler-explorer/powerpc64le/gcc-trunk-20240723/powerpc64le-unknown-linux-gnu
--with-sysroot=/opt/compiler-explorer/powerpc64le/gcc-trunk-20240723/powerpc64le-unknown-linux-gnu/powerpc64le-unknown-linux-gnu/sysroot
--enable-languages=c,c++,fortran,ada,d,objc,obj-c++,go
--with-pkgversion='crosstool-NG UNKNOWN' --enable-__cxa_atexit
--disable-libmudflap --disable-libgomp --disable-libssp --enable-libquadmath
--enable-libquadmath-support --disable-libsanitizer --disable-libmpx
--with-gmp=/opt/.build/powerpc64le-unknown-linux-gnu/buildtools
--with-mpfr=/opt/.build/powerpc64le-unknown-linux-gnu/buildtools
--with-mpc=/opt/.build/powerpc64le-unknown-linux-gnu/buildtools
--with-isl=/opt/.build/powerpc64le-unknown-linux-gnu/buildtools --enable-lto
--enable-threads=posix --enable-target-optspace --enable-plugin --disable-nls
--disable-multilib
--with-local-prefix=/opt/compiler-explorer/powerpc64le/gcc-trunk-20240723/powerpc64le-unknown-linux-gnu/powerpc64le-unknown-linux-gnu/sysroot
--enable-long-long
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 15.0.0 20240722 (experimental) (crosstool-NG UNKNOWN)