|
|
|
|
|
by mikeash
3186 days ago
|
|
"Can't" here means that your program is not well-formed otherwise, and the compiler assumes well-formedness. I assume you don't like that, but I wonder if you'd apply that to other optimizations? For a random example: int x = 42;
SomeFunc();
printf("%d\n", x);
Should the compiler be allowed to hard-code 42 as the second parameter to printf, or should it always store 42 to the stack before calling SomeFunc(), then loading back out? SomeFunc might lightly smash the stack and change the value of x, after all. |
|
There's a difference between assuming that a function like SomeFunc internally obeys the language semantics for the sake of code around its call site (this is the definition of modularity), and assuming that because the code around the call site "must" be "well-formed" this allows you to hallucinate whatever code you need to add elsewhere to retroactively make the call site "well-formed" (this is the definition of non-modularity).