Closed Frankkkkk closed 6 months ago
Hey, I think you should post this issue on the rustc
repository, it looks like a compiler topic indeed.
Thanks ! I've created the issue https://github.com/rust-lang/rust/issues/119572 . I'll close this one for now then :-)
Cheers
Hi,
I'm posting here first because I have an unexpected result on some code I wrote. It looks like a compiler issue but as I'm learning Rust, maybe it's just me doing dumb things :D. Could you please tell me is this is a misusage on my end before I raise the issue upstream ?
The code is here.
Basically, it consists of a
RefCell
that is written in an interrupt, and read on the main loop. The initial value is0
, and set to> 0
on the interrup. The main loop turns on the LED if the value is>0
. So it starts off and then turns on.(sorry for the rather strange code; I started removing logic to make a minimum MVP)
However, when there is no code on the
else
branch, the LED never turns on. If we put some code (like anop
, or something else) then it works as expected.For the sake of simplicity, I created two examples:
nop
in the else branch -> LED turns on.I tried to debug the compilation, and I see that:
MIR
The runtime optimized after MIR (006.000) looks okay on both cases:
GOOD:
BAD:
Basically, the diff is in
bb18
/bb19
LLVM-IR:
GOOD:
BAD:
I don't really know LLVM, but the
phi i8
that uses[0, %bb14]
looks strange to me, making the condition after always true ?Assembly
BAD:
To be honest I don't really understand instruction
24
; why would it try to load from0x0000
?What do you think ?
Many thanks for your help !