Using the following code with the following peep rule results in sdcc hanging. I don't necessarily expect sdcc to be able to support this; I understand it's recursive. Halt giving an error would also be a good solution.
/// GPL 2.0 or later
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
///< Move memory pointer to specified address to set value
uint16_t test(uint16_t address) {
return address >> 5;
}
// sdcc -mz80 --fverbose-asm ./peep.c -c && cat peep.asm
replace {
; GPL 2.0 or later
srl %1
rr %2
srl %1
rr %2
srl %1
rr %2
srl %1
rr %2
srl %1
rr %2
} by {
ld a, %2
srl %1
rra
srl %1
rra
srl %1
rra
srl %1
rra
srl %1
rra
ld %2, a
}
SDCC : z80/sm83/z80n/mos6502 TD- 4.3.6 #14522 (Linux)
Hmm. We could implement a counter for the number of peephole rules applied per function, and then stop with a warning if it goes over a threshold. I guess we'll need to experiment a bit to com up with a good limit that doesn't get triggered by "normal" use of SDCC, even when functions get big, and many rules apply. In general, each application of a rule tends to reduce code size or cycle count, so I guess a limit substantially above 2^16 should be fine, but still low enough to catch this kind of error.
Duplicate of [bugs:#3557].
Related
Bugs:
#3557