Open zq1997 opened 2 years ago
@llvm/issue-subscribers-clang-codegen
foo is calling bar which is not marked as noreturn, that's why it saves the callee-save registers.
foo is calling bar which is not marked as noreturn, that's why it saves the callee-save registers.
It doesn't need to care, it's not going to return anyway.
Infinite loop at the end seems to do the same thing as noreturn
attribute.
From what I know there is no way to get rid of the prologues in such cases.
The only thing that has to remain is stack allocation unless it can be proven that the stack won't underflow, stack allocated varisbles from lower level are not in use and there are no stack canaries involved. (gcc naked
attr removes also that, so it's not a solution)
while(1) {}
UB in C++ BTW
int foo() { }
is another UB, should not cause issues in this case with recent version of llvm/gcc
According to gcc list keeping prologue is intentionsal to allow backtracing (abort()
etc.) and throwing exceptions (under -fno-exceptions of course)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56165#c2
The only solution is to introduce new attribute be it noreturn_noexcept_nobacktrace
or some kind of custom ABI/calling convention attribute or abuse "prestacked annotation" I have proposed to solve risc-v interrupts. (e.g. __attribute__((prestacked("x1,x5-x31,f0-f31,fcsr")))
for an infinite loop function)
I have sent an official RFC for prestacked annotation https://discourse.llvm.org/t/rfc-prestacked-annotation-to-solve-risc-v-interrupt-stacking-mess/74120
That would solve the noreturn bloat if implemented on all archs.
If the function never returns, saving the callee-save registers is unnecessary. Then, how to disable these
push
s?