[Bug tree-optimization/84577] New: snprintf with null buffer not eliminated when return value is in a known range
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Feb 26 19:51:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84577
Bug ID: 84577
Summary: snprintf with null buffer not eliminated when return
value is in a known range
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 sprintf pass eliminates snprintf calls with a null buffer and zero size
when whose return value is a constant but it does not eliminate calls whose
return value is in some range. Both calls can be eliminated.
$ cat b.c && gcc -O2 -S -Wall -Wextra -fdump-tree-optimized=/dev/stdout b.c
void f (void)
{
int n = __builtin_snprintf (0, 0, "%hhx", 123); // eliminated
if (n < 0 || 2 < n)
__builtin_abort ();
}
void g (int i)
{
int n = __builtin_snprintf (0, 0, "%hhx", i); // not eliminated but could
be
if (n < 0 || 2 < n)
__builtin_abort ();
}
;; Function f (f, funcdef_no=0, decl_uid=1957, cgraph_uid=0, symbol_order=0)
f ()
{
<bb 2> [local count: 1073741825]:
return;
}
;; Function g (g, funcdef_no=1, decl_uid=1961, cgraph_uid=1, symbol_order=1)
g (int i)
{
<bb 2> [local count: 1073741825]:
__builtin_snprintf (0B, 0, "%hhx", i_3(D)); [tail call]
return;
}
More information about the Gcc-bugs
mailing list