On an embedded project, I recently had to debug a crash where the root cause was a division by zero. The offending code in question reduced to something like function foo()
presented here.
To validate that it actually was a division by zero problem, I added the if block that printed "GOTCHA". After this change, I saw that the processor status register (CFSR) had the UNDEFINST
bit set instead of the exepected DIVBYZERO
bit. What?
Using godbolt we can see the compiler emitting an instruction 0xdeff
in main... with no other code (suggesting that the compiler realized that the code will not work and simply stopped -- without warning, I might add).