Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#1336 -O3 error, using asm procedure

closed-invalid
nobody
gcc (462)
2012-06-14
2009-08-17
No

gcc -v

Reading specs from C:/Documents and Settings/Administrador/Mis documentos/Juan/C
ompiladores/C/MinGW/bin/../lib/gcc/mingw32/3.4.5/specs
Configured with: ../gcc-3.4.5-20060117-3/configure --with-gcc --with-gnu-ld --wi
th-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --dis
able-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --d
isable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --with
out-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enabl
e-hash-synchronization --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.5 (mingw-vista special r3)

C code:

void Test(void* c) {
asm("movl 8(%ebp), %eax \n\t"
"movaps (%eax), %xmm1 \n\t");
}
int main(int argc, char** argv) {
unsigned int c[10];
Test(&c);
return 0;
}

if i compile the code above using -O3 i get the following assembly output:

.file   "p.c"
.text
.p2align 4,,15

.globl _Test
.def _Test; .scl 2; .type 32; .endef
_Test:
pushl %ebp
movl %esp, %ebp
/APP
movl 8(%ebp), %eax
movaps (%eax), %xmm1

/NO_APP
popl %ebp
ret
.def ___main; .scl 2; .type 32; .endef
.p2align 4,,15
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
pushl %ebp
movl $16, %eax
movl %esp, %ebp
subl $56, %esp
andl $-16, %esp
call __alloca
call ___main
/APP
movl 8(%ebp), %eax
movaps (%eax), %xmm1

/NO_APP
leave
xorl %eax, %eax
ret

after the "call ___main" GCC is inserting the assembly code contained in the "Test" function in the body of the program, which isn't correct.
if i compile the C code using -O2 or without optimization it compiles correctly.

Discussion

  • Peter Hurley
    Peter Hurley
    2009-08-18

    This is functioning as designed. From the online gcc 3.4.6 manual http://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Optimize-Options.html#Optimize-Options:

    -finline-functions
    Integrate all simple functions into their callers. The compiler heuristically decides which functions are simple enough to be worth integrating in this way.
    If all calls to a given function are integrated, and the function is declared static, then the function is normally not output as assembler code in its own right.

    Enabled at level -O3.

     
  • Earnie Boyd
    Earnie Boyd
    2012-06-14

    See peterjhurley's comment.

     
  • Earnie Boyd
    Earnie Boyd
    2012-06-14

    • status: open --> closed-invalid