Given the following C++ (not C!) input file:
#include <stdio.h>
int main() {
while (1);
}
void oopsies() {
printf("tee hee fucky wucky :3");
}
Compiling this with clang 13 or newer, with -O1 or higher, results in the output:
> ./compiled
tee hee fucky wucky :3
Godbolt reveals the following output:
main: # @main
oopsies(): # @oopsies()
push rax
mov edi, offset .L.str
xor eax, eax
call printf
pop rax
ret
.L.str:
.asciz "tee hee fucky wucky :3"
which is uhhhhh Yeah Thats Not Right
what i think is happening:
- clang sees infinite loop and goes "ah cool, i don't need to insert a
rethere since this wont terminate - clang also decides to optimize out the infinite loop for Some Fucking Reason
- as a result, we're left with a completely empty
mainwith noret
is there like some undefined behaviour Spooky Activity going on here? why is it Do That? and why only for c++ and not c, where it correctly keeps the infinite loop?