Menu

#2399 Code Generator Internal Error When Use __sfr on Z80 If "--reserve-regs-iy" is Specified

closed-fixed
None
Z80
5
2016-08-05
2015-07-13
Tom Li
No

Tested Version

z80 3.5.2 #9283 (Linux, snapshot)

Description

Simple read/write operations on a __sfr, can crash the compiler easily when "--reserve-regs-iy" is specified.

Building the following code

__sfr __at 0x06 bank_a_page;

static unsigned char page_current;

int main(void)
{
    page_current = bank_a_page;
    bank_a_page = page_current;

    return 0;
}

with

$ sdcc debug.c -o debug -mz80 --reserve-regs-iy

leads to

debug.c:10: error 9: FATAL Compiler Internal Error in file '../../../src/z80/gen.c' line number '737' : code generator internal error
Contact Author with source code
debug.c:10: error 9: FATAL Compiler Internal Error in file '../../../src/z80/gen.c' line number '742' : Trying to assign a value to a literal
Contact Author with source code
debug.c:10: error 9: FATAL Compiler Internal Error in file '../../../src/z80/gen.c' line number '737' : code generator internal error
Contact Author with source code
debug.c:10: error 9: FATAL Compiler Internal Error in file '../../../src/z80/gen.c' line number '742' : Trying to assign a value to a literal
 Contact Author with source code
ld_cost op1: AOP_HL, op2: 4ld_cost op1: AOP_HL, op2: 4

Discussion

  • alvin

    alvin - 2016-05-24

    Small bump to indicate the bug is still present for the z80 in 3.5.6 #9605 (MINGW64).

    __sfr __at 0x1f IO8;               // 8-bit i/o port at 0x1f
    __sfr __banked __at 0xfbfe IO16;   // 16-bit i/o port at 0xfefe
    
    volatile unsigned char a;
    
    void main(void)
    {
       a = IO8;       // read port IO8
       IO8 = 100;     // write port IO8
    
       a = IO16;      // read port IO16
       IO16 = 200;    // write port IO16
    }
    

    sdcc -mz80 -S --reserve-regs-iy test.c

    ld_cost op1: AOP_HL, op2: 4ld_cost op1: AOP_HL, op2: 4ld_cost op1: AOP_HL, op2: 4ld_cost op1: AOP_HL, op2: 4
    zzzz.c:13: error 9: FATAL Compiler Internal Error in file '/home/sdcc-builder/build/sdcc-build/orig/sdcc/src/z80/gen.c' line number '740' : code generator internal error
    Contact Author with source code

    The bug only occurs for reading the i/o port into a global variable. If "a" is made local, there is no error. The difference is in the latter case, the result of the port read can be stored in an ix-indexed location whereas in the former case, sdcc insists on using iy to point at "a" and store the result which it can't do with "--reserve-regs-iy".

     
  • Erik Petrich

    Erik Petrich - 2016-08-05
    • status: open --> closed-fixed
    • assigned_to: Erik Petrich
     
  • Erik Petrich

    Erik Petrich - 2016-08-05

    Fixed in [r9711]

     

Log in to post a comment.