https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84562
Alexander Monakov <amonakov at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |amonakov at gcc dot gnu.org --- Comment #3 from Alexander Monakov <amonakov at gcc dot gnu.org> --- 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