https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84624
Bug ID: 84624 Summary: bogus -Wstringop-truncation in a catch statement and nul assignment outside it Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- The -Wstringop-truncation warning for the strncpy call below should have been suppressed by the subsequent assignment to d but the suppression logic is thwarted by the __cxa_end_catch () call. $ cat b.C && gcc -O2 -S -Wall -Wextra -fdump-tree-optimized=/dev/stdout b.C char d[3]; void f (); void g (const char *s) { try { f (); } catch (...) { __builtin_strncpy (d, s, sizeof d); // bogus warning } d[sizeof d - 1] = 0; // because of this } b.C: In function ‘void g(const char*)’: b.C:13:25: warning: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ specified bound 3 equals destination size [-Wstringop-truncation] __builtin_strncpy (d, s, sizeof d); // bogus warning ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ ;; Function g (_Z1gPKc, funcdef_no=0, decl_uid=2362, cgraph_uid=0, symbol_order=1) g (const char * s) { void * _1; <bb 2> [local count: 1073741825]: f (); <bb 3> [local count: 1073741825]: d[2] = 0; return; <bb 4> [count: 0]: <L1>: _1 = __builtin_eh_pointer (1); __cxa_begin_catch (_1); __builtin_strncpy (&d, s_7(D), 3); __cxa_end_catch (); goto <bb 3>; [100.00%] }