Open
Description
Bugzilla Link | 49599 |
Version | trunk |
OS | All |
CC | @chandlerc,@DMG862,@dwblaikie,@DougGregor,@emaste,@LebedevRI,@pogo59,@zygoloid,@oToToT |
Extended Description
Comment:
Clang 13 simply does not generate any code for f1 after the undefined behavior point. So any call onto f1 will eventually ends up fell into f2.
Although the compiler can do anything with an undefined behavior, including simply crashing, infinite loop, playing some music, or nuke the earth without violating the C++ specification. I still hope this undefined behavior won't be that surprising.
This issue is not observed in C frontend, or Clang 12.
Godbolt link for your convenience: https://godbolt.org/z/r3nWrE
Source code:
#include <stdio.h>
void f1(void) {
for(int i = 0; i >= 0; i++) {
// Undefined behavior
}
}
void f2(void) {
puts("Formatting /dev/sda1...");
// system("mkfs -t btrfs -f /dev/sda1");
}
// Prevents inlining
void (*volatile p1)(void) = f1;
void (*volatile p2)(void) = f2;
int main(void) {
puts(__VERSION__);
p1();
return 0;
}
Output:
Clang 13.0.0 (https://github.com/llvm/llvm-project.git fcdf7f6224610a51dc2ff47f2f1e3377329b64a7)
Formatting /dev/sda1...