https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88952
Bug ID: 88952 Summary: [powerpc] asm input from C expression with type larger than GPRs loads wrong value Product: gcc Version: 4.2.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: inline-asm Assignee: unassigned at gcc dot gnu.org Reporter: christopher.leonard at abaco dot com Target Milestone: --- When giving a C expression as input to an extended asm statement the wrong value is loaded if the type happens to be 64-bit (with 32-bit powerpc target). Happens regardless of optimization level, use of 'volatile'. Also happens in compiler explorer with GCC 4.8.5 <https://godbolt.org/z/hZAEEy>. This subtle behavior is not too hard to track down but will probably defy the expectations of the programmer, and could be introduced into a program with seemingly innocuous changes that result in the overall expression type being larger. I assume this is a bug and not the intention of the input operand feature. If this is the intended functionality I would suggest adding a warning for this situation. Source "ex.c": void bad_asm(void) { asm volatile ("stw %0, 50(0)" : :"r"(20ull)); } Build command: /opt/eldk/4.2/usr/ppc-linux/bin/gcc -mregnames -O3 -c -o ex.o ex.c Disassembly: ex.o: file format elf32-powerpc Disassembly of section .text: 00000000 <bad_asm>: 0: 39 20 00 00 li r9,0 4: 39 40 00 14 li r10,20 8: 91 20 00 32 stw r9,50(0) c: 4e 80 00 20 blr Output of gcc -v: Reading specs from /opt/eldk/4.2/usr/bin/../lib/gcc/powerpc-linux/4.2.2/specs Target: powerpc-linux Configured with: /opt/eldk/build/ppc-2008-04-01/work/usr/src/denx/BUILD/crosstool-0.43/build/gcc-4.2.2-glibc-20070515T2025-eldk/powerpc-linux/gcc-4.2.2/configure --target=powerpc-linux --host=i686-host_pc-linux-gnu --prefix=/var/tmp/eldk.UZpAG7/usr/crosstool/gcc-4.2.2-glibc-20070515T2025-eldk/powerpc-linux --disable-hosted-libstdcxx --with-headers=/var/tmp/eldk.UZpAG7/usr/crosstool/gcc-4.2.2-glibc-20070515T2025-eldk/powerpc-linux/powerpc-linux/include --with-local-prefix=/var/tmp/eldk.UZpAG7/usr/crosstool/gcc-4.2.2-glibc-20070515T2025-eldk/powerpc-linux/powerpc-linux --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit --enable-languages=c,c++,java --enable-shared --enable-c99 --enable-long-long --without-x Thread model: posix gcc version 4.2.2