-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Compiler generates wrong code for assigning struct fields #16621
Copy link
Copy link
Open
Labels
backend-llvmThe LLVM backend outputs an LLVM IR Module.The LLVM backend outputs an LLVM IR Module.bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviormiscompilationThe compiler reports success but produces semantically incorrect code.The compiler reports success but produces semantically incorrect code.
Milestone
Metadata
Metadata
Assignees
Labels
backend-llvmThe LLVM backend outputs an LLVM IR Module.The LLVM backend outputs an LLVM IR Module.bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviormiscompilationThe compiler reports success but produces semantically incorrect code.The compiler reports success but produces semantically incorrect code.
Zig Version
0.11.0-dev.4000+3022c525e
Steps to Reproduce and Observed Behavior
Hi
Firstly, thanks for the interesting new language (and tutorials & videos)!
I am playing with Zig for the past few months with STM32 MCU board (armv7 thumb2)
Compiler started to generate wrong machine code for this part of my STM32 code:
I would expect that after it runs value in Systick.CSR register will be 0x7 but it is 0x6. GDB:
I would also expect that example above will write 0x7 in the single pass but I'll leave that for the future investigation.
Systick is struct:
Noticed on 2023.07.01. with (I think) zig version 0.11.0-dev.3892.
Before it was working but I am not sure with which version.
Tested today with 0.11.0-dev.4000+3022c525e and problem still persist.
Platform is FreeBSD 14.0-CURRENT with LLVM16 from ports.
One of the workaround is to try to write additional bit to the Systick.CSR (which will be ignored):
Now GDB will show values for Systick.CSR: 0 -> 1 -> 3 -> 7
I'll try to create minimal example of this later.
Possible related to bug report #16615
Expected Behavior
After this code runs
Systick.CSR value should be 7