Can't create right alias to __saddr in IAR RL78 or it's a bug in optimization?

81 Views Asked by At

I think IAR loose __saddr atribute when creating alias

Assume we have SFR with next description:

    __saddr __no_init volatile union
    {
      unsigned char P3;
      __BITS8       P3_bit;
    } @ 0xFFF03;

Now we want to use P3 indirect, by alias:

   {
       auto &Px = P3;

       P3 = 0x55;
       Px = 0x55;
   }

Now look disassembly window:

    P3 = 0x55;
    02947     CD0355         MOV     S:__A_P3, #0x55
    Px = 0x55;
    0294A     3603FF         MOVW    HL, #0xFF03
    0294D     5155           MOV     A, #0x55
    0294F     9B             MOV     [HL], A

So, IAR can't use __saddr on alias or something wrong with my code?

Reproducing code:

// No real hardware need. This code can be run under simulator

#include <ior5f100aa.h> // Any MCU with an existing P3 can be used

// C++ program
int main(void)
{
    // write to register P3 (direct)
    P3 = 0x55;

    {
        // write to register P3 (indirect, using alias)
        auto& Px = P3;
        Px = 0x55;
    }
}

Comple, run, open disassembly window

    P3 = 0x55;
main():
_main:
    00136     CD0355         MOV     S:__A_P3, #0x55
        auto& Px = P3;
    00139     3603FF         MOVW    HL, #0xFF03
        Px = 0x55;
    0013C     5155           MOV     A, #0x55
    0013E     9B             MOV     [HL], A

[screenshot of disassembly window][1] [1]: https://i.stack.imgur.com/XuKGv.png

I see that direct write to P3 is shorter than writing by alias

0

There are 0 best solutions below