Open SihangZhu opened 3 months ago
Why does __builtin_alloca(0)
always returns the value of stack pointer?
I don't see any docs saying about that. https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005falloca https://clang.llvm.org/docs/LanguageExtensions.html#builtin-alloca
Why does
__builtin_alloca(0)
always returns the value of stack pointer?I don't see any docs saying about that. https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005falloca https://clang.llvm.org/docs/LanguageExtensions.html#builtin-alloca
Thank you for taking the time to answer. I found that x86 rearranges the addresses of variables on the stack, which is what causes the results to be inconsistent with gcc. But as you've also explained, builtin_alloca doesn't have this limitation. This optimization is also reasonable.
follow is example code
compiling commands:
clang++ -flto demo.cpp -o demo.exe -std=c++11
the result of this demo is "sp1 == sp2" compiled with gcc, while clang is "sp1 != sp2" Is there some wrong in llvm's lto