The (s51) simulator thinks that returning from a recursive function to itself is a "Jump to itself" and thus stops when "set opt selfjump_stop 1" is used. This makes the tcc/25_quicksort regression test fail with an abnormal stop when --no-peep is used.
_quicksort:
[...]
lcall _quicksort
00103$:
; cases/../tcc/25_quicksort.c:45: }
ret
With peephole optimizations enabled this becomes
_quicksort:
[...]
ljmp _quicksort
which prevents the stop and thus also prevents the false negative.
Is this the intended behaviour of selfjump_stop? If so, the regression tests should not use.
If not, then maybe it should also test for stack usage reduction.
Diff:
Diff:
Selfjump_stop option is used in MCS51 tests only. Is there any reason for it, or can it be turned off?
I'm going to introduce a new run mode in uCsim which is called "emulation", instead of "simulation". It skips some debugging features, including event breaks and selfjump_stop option, so it can be a little bit faster. The whole regtest stuff was able to run in this mode on my machine, so I think that selfjump-stop option is not really needed.
Well, you introduced it yourself in [r13426] to speed up the exit of broken programs:
"Faster exit from broken mcs51-xstack-auto program simulation"
The peephole optimizer which is normally used during compilation of the regression tests changes the problematic program flow and thus prevents triggering the selfjump_stop condition.
But the question is more if you really want to stop when a recursive call returns to itself while properly unwinding the stack.
I have not checked, but would it also stop on a DJNZ to itself? This is also a jump to itself, but not indefinitely. It's a perfect way to introduce some delay.
And then there are JB/JNB and CJNE direct/CJNE @Ri which could be used to wait for a volatile flag from an interrupt or for an sbit/sfr change.
So in my opinion this option of the simulator should not trigger on a RET or DJNZ instruction.
I am not certain about those flag situations.
And it seems valid for all other call and jump instructions.
Related
Commit: [r13426]
Last edit: Maarten Brock 2024-11-14
Ticket moved from /p/sdcc/bugs/3637/
Can't be converted:
I see that you have set this to pending. But what is it pending on?
Have you modified anything that I should test?
Should I clarify more what I think needs to be changed?
But have you also run them with
--no-peep?Or do you mean that the selfjump_stop option will disappear and that a real selfjump bug will have to be detected by the timeout mechanism?