Compiling the following C source: struct test { int a; };
static inline void test2(struct test *t) { register int a asm("r0") = (int) t; asm volatile ("swi #0" :: "r" (a)); } void test1(void) { struct test t; t.a = 0; test2(&t); } with "arm-elf-gcc test.c -S -O1" produces the following assembler output: .file "test.c" .text .align 2 .global test1 .type test1, %function test1: @ args = 0, pretend = 0, frame = 4 @ frame_needed = 0, uses_anonymous_args = 0 @ link register save eliminated. sub sp, sp, #4 mov r0, sp @ 8 "test.c" 1 swi #0 @ 0 "" 2 add sp, sp, #4 bx lr .size test1, .-test1 .ident "GCC: (GNU) 4.4.1" For the call to test2(), the pointer to struct test t is properly set up, but the content of the struct (t.a = 0) isn't. This is the case for -O1, -O2, -Os and -O3, but not for -O0, where gcc produces working code. arm-elf-gcc -v: Using built-in specs. Target: arm-elf Configured with: /var/tmp/gcc.uZt0/gcc-4.4.1/configure --enable-languages=c --with-mpfr=/usr/local --without-headers --target=arm-elf --prefix=/usr/local/arm-elf --with-local-prefix=/usr/local/arm-elf --disable-werror --enable-multilib --enable-shared --disable-nls --disable-libssp --with-arch=armv4t --with-cpu=arm7tdmi-s Thread model: single gcc version 4.4.1 (GCC) -- Summary: gcc produces broken code when passing struct pointer to static inline function with asm() Product: gcc Version: 4.4.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: inline-asm AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: agraf at znc dot in GCC target triplet: arm-elf http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42984