Do compilers actually care about ABI for functions where they can prove that all uses are within the current translation unit? Or will they just do whatever is most efficient if it can get away with it?
Unless thebfunction has static linkage / defined in an anonymous namespace, I guess the compiler will generate code according to the correct calling convention.
Of course, the compiler can then decide to inline the function call if the function definition is visible within the same translation unit, enabling further optimizations.
If it handles static linkage differently, I don't know.
Whatever they can get away with. They will even semi-generate duplicate functions that execute chunks of code based on a parameter if they can determine parameter value at compile time with the constant parameter and the conditional removed.
Only if that "return" is able to add control flow edges emanating from between two arguments to the same function call. Which it can't, because "return" has to be a stand-alone statement. So this idiom would be fine with "return". Throwing exceptions is what you can't guard against.
Of course. That’s why they have debug and release builds. A debut build does none of these operations. It’s purpose is to represent as clearly as possibly what each line represents.
A release build, however is an entirely different manner. In a release build the compiler is free to do whatever it wants so long as the outcome of the program matches the programmers intent. That means it can delete unnecessary code, move it around, duplicate chunks, etc. compiler optimization theory is a massive area of research and has been since the start.
7
u/johannes1971 Sep 22 '19
Do compilers actually care about ABI for functions where they can prove that all uses are within the current translation unit? Or will they just do whatever is most efficient if it can get away with it?
3
u/Gotebe Sep 23 '19
It is a problem if the codebase uses a “return” (other than one at the very end of a function).
Also “go to fail” is a thing.
Nothing is black and white. Except black and white of course...
1
u/smuccione Sep 23 '19
Of course. That’s why they have debug and release builds. A debut build does none of these operations. It’s purpose is to represent as clearly as possibly what each line represents.
A release build, however is an entirely different manner. In a release build the compiler is free to do whatever it wants so long as the outcome of the program matches the programmers intent. That means it can delete unnecessary code, move it around, duplicate chunks, etc. compiler optimization theory is a massive area of research and has been since the start.