https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84562
--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> --- (In reply to Alexander Monakov from comment #3) > It's not just -faggressive-loop-optimizations, it seems that constructors of > weak globals are available for folding, and I really doubt that's actually > intended; after all, GCC does always consider weak function interposable, so > why not objects? Compare: > > __attribute__((weak)) const int x=0; int f(){return x==0;} > > f: > movl $1, %eax > ret > > vs. > > __attribute__((weak)) int x(void){return 0;} int f(){return x()==0;} > > f: > subq $8, %rsp > call x > testl %eax, %eax > sete %al > movzbl %al, %eax > popq %rdx > ret I agree this inconsistency is odd (verified other compilers behave the same).