[llvm-dev] const struct auto vs. static

Friedman, Eli via llvm-dev llvm-dev at lists.llvm.org
Mon Apr 2 14:34:44 PDT 2018


On 4/1/2018 10:31 PM, Jay K via llvm-dev wrote:
> 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.

This is controlled by -fmerge-all-constants/-fno-merge-all-constants.  
It's on by default with clang, off by default with gcc.

-Eli

-- 
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project



More information about the llvm-dev mailing list