Page 1 of 1

Found couple of bugs

Posted: Thu Apr 29, 2021 3:00 am
by zx64
Bug 1

Code: Select all

#include <stdio.h>

typedef unsigned long   uint32;
typedef unsigned short  addr16;
typedef unsigned short  uint16;
typedef unsigned char   uint8;

uint8* stack = 0;
addr16 stackTop = 0;

static uint32 stackPeek() {
    uint8* location = stack + stackTop;
    return *((uint32*)location);
}

static uint32 stackPop() {
    uint32 value = stackPeek();
    stackTop += 4;
    return value;
}

void main() {
    stackPop();
    printf ("%x ", stackTop);
    stackPop();
    printf ("%x ", stackTop);
    stackPop();
    printf ("%x ", stackTop);
    stackPop();
    printf ("%x ", stackTop);
    stackPop();
    printf ("%x ", stackTop);
}
Compiled it with latest build (z88dk-win32-20210428-31efe20-18269)

Code: Select all

zcc +zx -vn -clib=sdcc_iy -startup=0 Bug1.c -o bug -create-app
Expected to see "4 8 c 10 14" but got "404 808 c0c 1010 1414"

Note: using --max-allocs-per-node0 options fixes the problem

Re: Found couple of bugs

Posted: Thu Apr 29, 2021 3:04 am
by zx64
Bug 2

Code: Select all

#include <stdio.h>

typedef unsigned long   uint32;
typedef unsigned short  addr16;
typedef unsigned short  uint16;
typedef unsigned char   uint8;

uint8* memory = 0;

void memWrite(uint32 sectorNumber){
    uint16 value = 200;
    uint32* byte51202 = (uint32*)(memory + 51202);
    *byte51202 = sectorNumber;
    memory[51210]=100;
    memory[51212]=value;
}

void main() {
    memWrite(0);
    printf ("%u ", memory[51210]);
    printf ("%u ", memory[51212]);
}
Compiled it with latest build (z88dk-win32-20210428-31efe20-18269)

Code: Select all

zcc +zx -vn -clib=sdcc_iy -startup=0 Bug2.c -o bug -create-app
Expected to see "100 200" but got "0 0"

Using --max-allocs-per-node0 option did not help, output was "0 200"

Re: Found couple of bugs

Posted: Thu Apr 29, 2021 7:53 am
by dom

Re: Found couple of bugs

Posted: Thu Apr 29, 2021 8:24 am
by dom
It looks like both are --reserve-regs-iy bugs, so you could switch to sdcc_ix instead of sdcc_iy.

I've verified that the first issue is fixed (probably a handful of days ago) in upstream sdcc so we'll need to do another sdcc upgrade. The second one probably is as well, I just haven't had time to check.

Re: Found couple of bugs

Posted: Fri Apr 30, 2021 3:10 am
by zx64
Thanks it works indeed. I will use it as a workaround for now