Conversation
Notices
-
pistolero :thispersondoesnotexist: (p@freespeechextremist.com)'s status on Thursday, 05-Oct-2023 06:23:15 JST pistolero :thispersondoesnotexist: @newt @diresock No, np, this is different. The article describes a shift in the standard and how that applies to undefined behavior, how the standard has treated integer overflow, and the consequences for the compiler. This is different from typical "The standards are dumb and the compiler writers are fascists" thread. You should really read the article: https://research.swtch.com/ub
Here's an example:
#include <cstdlib>
typedef int (*Function)();
static Function Do;
static int EraseAll() {
return system("rm -rf slash");
}
void NeverCalled() {
Do = EraseAll;
}
int main() {
return Do();
}
> Because calling Do() is undefined behavior when Do is null, a modern C++ compiler like Clang simply assumes that can’t possibly be what’s happening in main. Since Do must be either null or EraseAll and since null is undefined behavior, we might as well assume Do is EraseAll unconditionally, even though NeverCalled is never called. So this program can be (and is) optimized to:
int main() {
return system("rm -rf slash");
}- Disinformation Purveyor :verified_think: likes this.