The C11 standard appears to imply that iteration statements with constant controlling expressions should not be optimized out. I\'m taking my advice from this answer, which
It seems that this is a bug in the Clang compiler. If there isn't any compulsion on the die() function to be a static function, do away with static and make it inline:
#include
inline void die(void) {
while(1)
;
}
int main(void) {
printf("begin\n");
die();
printf("unreachable\n");
}
It's working as expected when compiled with the Clang compiler and is portable as well.
Compiler Explorer (godbolt.org) - clang 9.0.0 -O3 -std=c11 -pedantic-errors
main: # @main
push rax
mov edi, offset .Lstr
call puts
.LBB0_1: # =>This Inner Loop Header: Depth=1
jmp .LBB0_1
.Lstr:
.asciz "begin"