public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/37386]  New: Interrupt service routine for arm target corrupts program counter
@ 2008-09-05 17:53 fede dot tft at hotmail dot it
  2008-09-05 18:42 ` [Bug c++/37386] " fede dot tft at hotmail dot it
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: fede dot tft at hotmail dot it @ 2008-09-05 17:53 UTC (permalink / raw)
  To: gcc-bugs

Trying to compile this code:

#define U0THR          (*((volatile unsigned char *) 0xE000C000))

template <typename T, unsigned int len>
class Queue
{
        public:
        /**
        Constructor, create a new queue.
        */
        Queue()
        {
                put_pos=get_pos=num_elem=0;
        }

        bool IRQget(T& elem)
        {
                if((put_pos==get_pos)&&(num_elem==0))//If queue empty
                {
                        return false;
                }
                num_elem--;
                elem=buffer[get_pos];
                if(++get_pos==len) get_pos=0;
                return true;
        }

        bool IRQput(T elem)
        {
                if((put_pos==get_pos)&&(num_elem!=0))//If queue full
                {
                        return false;
                }
                num_elem++;
                buffer[put_pos]=elem;
                if(++put_pos==len) put_pos=0;
                return true;
        }

        private:
        //Queue data
        T buffer[len];
        volatile unsigned int num_elem;
        volatile unsigned int put_pos;
        volatile unsigned int get_pos;
};

Queue<char,32> tx_queue;

void serial_IRQ_Routine()   __attribute__ ((interrupt("IRQ")));
void serial_IRQ_Routine()
{
        char c;
        int i;
        for(i=0;i<16;i++)
        {
                //If software queue empty, stop
                if(tx_queue.IRQget(c)==false) break;
                U0THR=c;
        }
}

with gcc 4.2.4, command line "arm-elf-g++ -mcpu=arm7tdmi -fno-exceptions
-fno-rtti -Os -Wall -S bug.cpp"
corrupts the program counter when returning from the ISR.
It happens only with -Os optimization flag. -O0 -O1 -O2 -O3 optimization flags
cause no bug.

Here's a piece of assembler code:

_Z18serial_IRQ_Routinev:
        @ Interrupt Service Routine.
        @ args = 0, pretend = 0, frame = 4
        @ frame_needed = 0, uses_anonymous_args = 0
        sub     lr, lr, #4
        stmfd   sp!, {r0, r1, r2, r3, r4, r5, r6, r7, ip, lr}
        ldr     r7, .L15
        sub     sp, sp, #4
        ldr     r6, .L15+4
        mov     r4, #0
        add     r5, sp, #3
.L10:
        ldr     r0, .L15+8
        mov     r1, r5
        mov     lr, pc
        bx      r7
        cmp     r0, #0
        add     r4, r4, #1
        beq     .L13
        ldrb    r3, [sp, #3]    @ zero_extendqisi2
        cmp     r4, #16
        strb    r3, [r6, #0]
        bne     .L10
.L13:
        add     sp, sp, #4
        ldmfd   sp!, {r0, r1, r2, r3, r4, r5, r6, r7, ip, lr}
        subs    pc, lr, #4

at the beginning there's
"       sub     lr, lr, #4"
and at the end
"       subs    pc, lr, #4"
so the program counter is decremented by 8 instead of 4.

Here's the output of arm-elf-gcc -v:

arm-elf-g++ -v
Using built-in specs.
Target: arm-elf
Configured with: ../gcc-4.2.4/configure --target=arm-elf
--prefix=/usr/local/arm-elf --enable-interwork --enable-multilib
--with-float=soft --enable-languages=c,c++ --with-newlib
--with-headers=../newlib-1.16.0/newlib/libc/include
Thread model: single
gcc version 4.2.4


-- 
           Summary: Interrupt service routine for arm target corrupts
                    program counter
           Product: gcc
           Version: 4.2.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fede dot tft at hotmail dot it


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/37386] Interrupt service routine for arm target corrupts program counter
  2008-09-05 17:53 [Bug c++/37386] New: Interrupt service routine for arm target corrupts program counter fede dot tft at hotmail dot it
@ 2008-09-05 18:42 ` fede dot tft at hotmail dot it
  2009-05-13 12:31 ` [Bug target/37386] " ramana at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: fede dot tft at hotmail dot it @ 2008-09-05 18:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from fede dot tft at hotmail dot it  2008-09-05 18:40 -------
After searching the bug database, it looks like this bug is similar to bug
#27859 and bug #16634, but in this case occurs only with -Os


-- 


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/37386] Interrupt service routine for arm target corrupts program counter
  2008-09-05 17:53 [Bug c++/37386] New: Interrupt service routine for arm target corrupts program counter fede dot tft at hotmail dot it
  2008-09-05 18:42 ` [Bug c++/37386] " fede dot tft at hotmail dot it
@ 2009-05-13 12:31 ` ramana at gcc dot gnu dot org
  2009-05-13 18:53 ` fede dot tft at hotmail dot it
  2009-12-11 18:16 ` ramana at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: ramana at gcc dot gnu dot org @ 2009-05-13 12:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from ramana at gcc dot gnu dot org  2009-05-13 12:31 -------
This appears to be fixed with trunk as of r147467. Can you reproduce this with
4.3 or 4.4 ? If not we can close this one out.

_Z18serial_IRQ_Routinev:
        @ Interrupt Service Routine.
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        stmfd   sp!, {r0, r1, r2, r3, r4, ip}
        mov     r2, #0
        ldr     r3, .L9
        ldr     r0, .L9+4
        mov     r1, r2
.L6:
        ldr     r4, [r3, #36]
        ldr     ip, [r3, #40]
        cmp     r4, ip
        bne     .L2
        ldr     ip, [r3, #32]
        cmp     ip, #0
        beq     .L1
.L2:
        ldr     ip, [r3, #32]
        sub     ip, ip, #1
        str     ip, [r3, #32]
        ldr     ip, [r3, #40]
        ldr     r4, [r3, #40]
        add     r4, r4, #1
        str     r4, [r3, #40]
        ldr     r4, [r3, #40]
        ldrb    ip, [r3, ip]    @ zero_extendqisi2
        cmp     r4, #32
        add     r2, r2, #1
        streq   r1, [r3, #40]
        cmp     r2, #16
        strb    ip, [r0, #0]
        bne     .L6
.L1:
        ldmfd   sp!, {r0, r1, r2, r3, r4, ip}
        subs    pc, lr, #4
.L10:
        .align  2
.L9:


-- 

ramana at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/37386] Interrupt service routine for arm target corrupts program counter
  2008-09-05 17:53 [Bug c++/37386] New: Interrupt service routine for arm target corrupts program counter fede dot tft at hotmail dot it
  2008-09-05 18:42 ` [Bug c++/37386] " fede dot tft at hotmail dot it
  2009-05-13 12:31 ` [Bug target/37386] " ramana at gcc dot gnu dot org
@ 2009-05-13 18:53 ` fede dot tft at hotmail dot it
  2009-12-11 18:16 ` ramana at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: fede dot tft at hotmail dot it @ 2009-05-13 18:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from fede dot tft at hotmail dot it  2009-05-13 18:53 -------
(In reply to comment #2)
> This appears to be fixed with trunk as of r147467. Can you reproduce this with
> 4.3 or 4.4 ? If not we can close this one out.

Tested with GCC 4.3.2, the bug is fixed.


-- 


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/37386] Interrupt service routine for arm target corrupts program counter
  2008-09-05 17:53 [Bug c++/37386] New: Interrupt service routine for arm target corrupts program counter fede dot tft at hotmail dot it
                   ` (2 preceding siblings ...)
  2009-05-13 18:53 ` fede dot tft at hotmail dot it
@ 2009-12-11 18:16 ` ramana at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: ramana at gcc dot gnu dot org @ 2009-12-11 18:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from ramana at gcc dot gnu dot org  2009-12-11 18:16 -------
Fixed with 4.3.2 apparently.


-- 

ramana at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.3.2


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-12-11 18:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-05 17:53 [Bug c++/37386] New: Interrupt service routine for arm target corrupts program counter fede dot tft at hotmail dot it
2008-09-05 18:42 ` [Bug c++/37386] " fede dot tft at hotmail dot it
2009-05-13 12:31 ` [Bug target/37386] " ramana at gcc dot gnu dot org
2009-05-13 18:53 ` fede dot tft at hotmail dot it
2009-12-11 18:16 ` ramana at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).