Menu

#2673 volatile handling bug in lospre

closed-fixed
None
redundancy elimination
7
2018-07-14
2017-10-22
No

In current SDCC 3.6.9 #10093, the following code

struct
{
    volatile int x;
} s;

void f(void)
{
    s.x & 5;
    while(s.x & 5);
}

Reads s.x only once. This is probably a bug in lospre, since the generated asm seems correct when using --nolospre.

Philipp

P.S.: This issues was first found and reported by Daniel Drotos on the sdcc-user mailing list. I just verified, tested, created a code sample to reproduce the issue and filed the bug report.

Discussion

  • Philipp Klaus Krause

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -16,3 +16,5 @@
     Reads s.x only once. This is probably a bug in lospre, since the generated asm seems correct when using --nolospre.
    
     Philipp
    +
    +P.S.: This issues was first found and reported by Daniel Drotos on the sdcc-user mailing list. I just verified, tested, created a code sample to reproduce the issue and filed the bug report.
    
     
  • 笑行天下

    笑行天下 - 2018-04-17

    confirmed on 3.7.0 and latest snapshot r10385, the following sample code also cause the problem:

    void test1(volatile uint8_t* status)
    {
        status[0] & 0x08;
        while (status[0] & 0x08) {}
    }
    
    void test2(volatile uint8_t* status)
    {
        while (status[0] & 0x04) {}
        while (status[0] & 0x08) {}
    }
    
     
  • 笑行天下

    笑行天下 - 2018-05-14

    Tried to modify SDCC source code, it seems that the patch in the attachment could fix the problem.

     
  • Philipp Klaus Krause

    I'm looking into this, and hope to have a fix in the next few days. The patch would indeed fix the bug, but would also disable some valid optimizations, so I'll see if I can come up with a solution that allows for more optimizations on volatile variables.

    Philipp

     
  • Philipp Klaus Krause

    • status: open --> closed-fixed
    • assigned_to: Philipp Klaus Krause
     
  • Philipp Klaus Krause

    Fixed in [r10473].

    Philipp

     

Log in to post a comment.

Monday.com Logo