I find it surprising that given this:
void f1()
{
const struct { int a; } b = { 0 };
}
that clang does not put b on the stack.
gcc does. My gut feeling says it belongs on stack.
But perhaps, the thing is, it is const, and location
shouldn't matter to most code, as long as lifetime is adequate.
Almost no code could tell the difference.
But we have code that takes the address of things, and other things
and wants them in range, i.e. all on the stack.
I had to remove const to make it work.
I realize such code is troublesome in the face of inlining.
We should probably mark some of our functions to not be inlined.
$ cat 3.c
void f2(const void*);
void f1()
{
const struct { int a; } b = { 0 };
f2(&b);
}
$ clang -c -S 3.c
$ cat 3.s
_f1: ## @f1
pushq %rbp
movq %rsp, %rbp
leaq _f1.b(%rip), %rax
movq %rax, %rdi
callq _f2
popq %rbp
retq
$ clang --version
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Thank you,
- Jay