Currently, Clang will always optimize this to return 3:
static int inner(int a) {
return a + 1;
}
int outer() {
return inner(2);
}
Notably, this happens even if inner is marked noinline, because of the Interprocedural Sparse Conditional Constant Propagation pass.
This is unhelpful for various use cases, including:
testing the compiler's code generation
defining a dummy function whose purpose is to be a place to break in a debugger
GCC has a function attribute noipa, whose effect is (to quote the manual):
Disable interprocedural optimizations between the function with this attribute and its callers, as if the body of the function is not available when optimizing callers and the callers are unavailable when optimizing the body.
It would be good to support this in LLVM/Clang as well.
Extended Description
Currently, Clang will always optimize this to
return 3
:static int inner(int a) { return a + 1; } int outer() { return inner(2); }
Notably, this happens even if inner is marked
noinline
, because of the Interprocedural Sparse Conditional Constant Propagation pass.This is unhelpful for various use cases, including:
GCC has a function attribute
noipa
, whose effect is (to quote the manual):It would be good to support this in LLVM/Clang as well.