| ▲ | rcxdude 10 hours ago | |||||||
The CPU doesn't really see functions, it just sees instructions. Functions are a convention on top of the machine code. What happens in this case is the compiler emits essentially a malformed function: it ends without performing a return, so execution just continues into the next function in memory. You can get the same behaviour by missing a 'return' statement from a function that needs one (though in that case I've also seen kind of the opposite: the function returns into the function two slots up in the stack, essentially returning from the function that called it! Undefined behaviour can utterly destroy normal control flow). Probably the process was one optimization pass saw that the function will never return due to an infinite loop, and removed the function return from the IR of the function, then a later pass saw that the infinite loop was a no-op and undefined so removed that as well, leaving a function that basically did nothing, not even return. | ||||||||
| ▲ | echoangle 10 hours ago | parent [-] | |||||||
> The CPU doesn't really see functions, it just sees instructions. Functions are a convention on top of the machine code. Not really true, most instructions set have instructions specifically to implement functions as found in normal programming languages. x86 has CALL and RET for example. https://en.wikipedia.org/wiki/X86_calling_conventions Of course the compiler can stil optimize by inlining etc., but functions still mostly exist at the assembly level. | ||||||||
| ||||||||