https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102238
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks|102216 |84774 Last reconfirmed| |2021-09-16 Status|UNCONFIRMED |NEW See Also| |https://gcc.gnu.org/bugzill | |a/show_bug.cgi?id=102216 Ever confirmed|0 |1 --- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> --- Confirmed with the simplified test case below. DOM3 is the last pass to run before strlen. The strlen output shows the sprintf call is being folded to strcpy. I'm not sure what the relationship of this bug is to pr102216 but a missing -Wrestrict cannot be a cause of a missed optimization. I've moved pr102216 to See Also. $ cat pr102238.c && gcc -O2 -S -Wall -fdump-tree-dom3=/dev/stdout pr102238.c struct A { char a[4]; }; struct B { struct A a1, a2; }; void f (struct B *p) { enum { off = __builtin_offsetof (struct B, a2.a) }; char *s = (char*)p + off; char *d = p->a2.a; __builtin_sprintf (d, "%s", s); // missing -Wrestrict } ;; Function f (f, funcdef_no=0, decl_uid=1983, cgraph_uid=1, symbol_order=0) ;; 1 loops found ;; ;; Loop 0 ;; header 0, latch 1 ;; depth 0, outer -1 ;; nodes: 0 1 2 ;; 2 succs { 1 } void f (struct B * p) { char * d; char * s; <bb 2> [local count: 1073741824]: s_2 = p_1(D) + 4; d_3 = &p_1(D)->a2.a; __builtin_sprintf (d_3, "%s", s_2); return; } Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84774 [Bug 84774] [meta-bug] bogus/missing -Wrestrict https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102216 [Bug 102216] [12 Regression] missed optimization causing Warray-bounds