Compiling the code:

   extern void doSomething(unsigned v);
   void irq_() __attribute__ ((interrupt("IRQ")));

   void irq_()
   {
    unsigned v;
    doSomething(v);
   }

with: 

  arm-elf-g++ -O0\
   -fno-exceptions\
   -fomit-frame-pointer\
   -S -o irq-bug.s\
   irq-bug.cc

results in:

        .file   "irq-bug.cc"
        .text
        .align  2
        .global _Z4irq_v
        .type   _Z4irq_v, %function
_Z4irq_v:
        @ Interrupt Service Routine.
        @ args = 0, pretend = 0, frame = 4
        @ frame_needed = 0, uses_anonymous_args = 0
        sub     lr, lr, #4            @<------------------- (1)
        stmfd   sp!, {r0, r1, r2, r3, ip, lr}
        sub     sp, sp, #4
        ldr     r0, [sp, #0]
        bl      _Z11doSomethingj
        add     sp, sp, #4
        ldmfd   sp!, {r0, r1, r2, r3, ip, lr}
        subs    pc, lr, #4            @<------------------- (2)
        .size   _Z4irq_v, .-_Z4irq_v
        .ident  "GCC: (GNU) 4.1.1"

Remarks:
 - the lr register is decremented twice (1) (2)
 - the -O0 and -fomit-frame-pointer switches are relevant
 - arm-elf-g++ -v:
    Using built-in specs.
     Target: arm-elf
     Configured with: 
      /home/buchmann/devel/gcc/dist/gcc-4.1.1/configure -v 
       --prefix=/home/buchmann/devel/gcc/targets/arm/ 
       --target=arm-elf --enable-languages=c,c++,java 
       --disable-threads 
       --disable-shared 
       --disable-multilib 
       --with-as=/home/buchmann/devel/gcc/targets/arm/arm-elf/bin/as 
       --with-ld=/home/buchmann/devel/gcc/targets/arm/arm-elf/bin/ld 
       --with-newlib 
       --without-headers
     Thread model: single
     gcc version 4.1.1


Best regards

Hans Buchmann


-- 
           Summary: Wrong Code for ARM IRQ routine
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hans dot buchmann at fhso dot ch
 GCC build triplet: i386-pc-linux-gnu
  GCC host triplet: i386-pc-linux-gnu
GCC target triplet: arm-elf


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29004

Reply via email to