https://gcc.gnu.org/bugzilla/show_bug.cgi?id=20641
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |msebor at gcc dot gnu.org --- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> --- The test case in comment #0 is optimized as expected but not because of attribute malloc but rather because x is static and function f is not defined in the same translation unit, meaning it can't access x. The test case is optimized on this basis even without attribute malloc: $ cat x.c && gcc -O2 -S -Wall -Wextra -Wpedantic -fdump-tree-optimized=/dev/stdout x.c extern int* f (void); static int x; void g (void) { int *p = &x; int *q = f (); *p = 12; *q = 8; if (*p != 12) __builtin_abort (); } ;; Function g (g, funcdef_no=0, decl_uid=1798, cgraph_uid=0, symbol_order=1) g () { int * q; <bb 2>: q_4 = f (); x = 12; *q_4 = 8; return; }