Menu

#3242 z80 miscompilation with default options

closed-fixed
None
Z80
5
2021-05-18
2021-05-18
dom
No

Another one from the land of z88dk, this was found with r12285, but also present in vanilla r12388:

#include <stdio.h>

typedef unsigned short uint16;

uint16 x, y;

static uint16 printHello() {
    printf("\nHello");
    return 1;
}

static uint16 hello(uint16 a, uint16 b) {
    uint16 result = 0;
    if(a + b > x - y){
        result = printHello();
    }
    return result;
}

void main() {
    x = 2000;
    y = 1000;
    hello(600,600);
}

We expect "Hello" to be printed, defective code generated is:

        ld      hl, #_y
        ld      a, (_x+0)
        sub     a, (hl)
        ld      h, a      <<<<<
        inc     hl
        ld      a, (_x+1)
        sbc     a, (hl)
        ld      l, a
        ld      a, h
        sub     a, c
        ld      a, l
        sbc     a, b

Compilation:

  • Default z80 options (-mz80 -S)
  • Compiling with --max-allocs-per-node0 generates different code without this issue

Discussion

  • Philipp Klaus Krause

    Thanks. I can reproduce the issue on my Debian GNU/Linux testing system.

     
  • Philipp Klaus Krause

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

    Fixed in [r12390].

     

    Last edit: Maarten Brock 2021-05-22

Log in to post a comment.