-
Notifications
You must be signed in to change notification settings - Fork 7.3k
K_SPINLOCK() on single core SOC fails to build with optimization -Og #78066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It turned out hat compiling with replication procedure: if you want to test yourself, just add
to the (and paste the above code to your |
Actually, shouldn't it be irrelavant which optimization level ? |
So far, I have been unable to reproduce this. Which compiler (and version) are you using? Also, what board are you building for? Thinking aloud ... at its core, K_SPINLOCK is a for-loop construct. If the compiler is generating the warning you described, my initial thoughts are that it is determining that the body of the for-loop might not execute. For that to occur, its local spinlock key __i.key would have a non-initialized value which could then potential be non-zero. However, the way it is constructed, it should have an initial value of 0. This makes me think that either ... |
Using RISCV toolchain for qemu from latest zephyr 3.7.99 board: qemu_riscv32/qemu_virt_riscv32 CMakeLists.txt added this at the very bottom
my main looks like this:
@peter-mitsis just for the full picture. I agree, that for some reason the compiler seems a little distracted and assumes there is an option where this can be bypassed. however when actually executing and debugging. I never saw it uninitialized. so the real question is why is gcc so cautious about the for loop prediction based on plus there is still an option that I am completely off. and doing stupid things without noticing. so a confirmation from your side is needed to prove, there is something or not. |
Likely[1] this is going to be down to -Og disabling whatever pass was folding/eliding/removing the loop test, so it doesn't know for sure that the loop will execute at least once, thus the assignment to Obviously the workaround for the specific code in question is just to initialize Beyond that... I guess my gut says this isn't worth fixing unless we want to enable a "debug build" at that optimization level as an official feature. The workaround is trivial. But if we do, the form would be to refactor the test expression so that it's always guaranteed to be true the first time it's called. [1] The other possibility is a toolchain bug, but that's pretty rare. |
Additional info: A little extra digging suggests that the reported behavior was introduced somewhere in GCC version 12, as I am not seeing it on GCC version 11. Furthermore, I am not seeing this behavior on any optimization level except -Og (I tried using O0, O1, O2, O3, Oz, Os and Og). I am thinking that this is a toolchain issue, as it makes little sense to me as to why only that optimization should generate the warning/error. In the meantime, my recommendation would be to employ the suggested workaround. |
Yeah, agreed. I'm going to WONTFIX this. Please reopen with impact details if that's not acceptable. |
it took me some time to figure out that the issue comes from compiling with -Og. so just to avoid anybody else wastes a lot of time (like me). is it possible to add something to cmake => "please dont use -Og, there might be issues with the riscv toolchain" ? |
I actually do not understand and may need a quick guess, where to look.
this compiles without errors
but this:
fails - as far as I understand that should be the same as above.
if you wonder, why I am asking, its about this here:
zephyr/drivers/serial/uart_emul.c
Line 922 in 8b8b0a0
The text was updated successfully, but these errors were encountered: