-
Notifications
You must be signed in to change notification settings - Fork 246
Description
Hi, it's me again, the guy with the weird problems. This time, I believe I have a decent grasp on what's going wrong. It's documented with a minimal example and a README here: https://github.com/tronje/llvm-avr-compiler-bug
The short version is that under certain conditions, the Y
register is used to load struct members into registers, as an optimization. This causes stack corruption (maybe?) and causes incorrect program behavior. I do believe I did a decent job explaining it in the README of the project I linked. The Rust code should be fairly self-explanatory as well.
It does include some weird things, like extra booleans to get the struct to be a certain size, without which the bug does not occur.
Reasons I suspect the Y
register to be the culprit:
In order to access stack locations, avr-gcc will set up a 16-bit frame pointer in R29:R28 (Y) because the stack pointer (SP) cannot be used to access stack slots.
And whenever the example program is changed in a way that does not cause the bug to occur, the offending use of Y
is also not included in the assembly.
I hope it's okay to report this here; I realize this is just avr-hal, not LLVM 🙂 But I was hoping to get an opinion and perhaps some advice on how to proceed here. Thanks!