[Bug tree-optimization/78969] bogus snprintf truncation warning due to missing range info
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Jan 2 19:32:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78969
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic,
| |missed-optimization
--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
The same underlying problem (lack of range info) can be seen in the VRP dump
for the following test case. The -Walloca-larger-than option is interesting
because the alloca pass that implements it tries to compensate for the missing
range info by deriving it from conditions the alloca() argument is subjected to
(see the alloca_call_type_by_arg function). Although the logic it uses is
quite simple in this case it manages to successfully determine the range on its
own and avoids the warning.
$ cat t.c && gcc -O2 -S -Wall -Walloca-larger-than=255
-fdump-tree-vrp=/dev/stdout t.c
void foo (void*);
void f (unsigned long j)
{
if (j / 256)
return;
foo (__builtin_alloca (j));
}
;; Function f (f, funcdef_no=0, decl_uid=1797, cgraph_uid=0, symbol_order=0)
;; 1 loops found
;;
;; Loop 0
;; header 0, latch 1
;; depth 0, outer -1
;; nodes: 0 1 2 3 4
;; 2 succs { 4 3 }
;; 3 succs { 4 }
;; 4 succs { 1 }
SSA replacement table
N_i -> { O_1 ... O_j } means that N_i replaces O_1, ..., O_j
j_7 -> { j_3(D) }
Incremental SSA update started at block: 2
Number of blocks in CFG: 5
Number of blocks to update: 2 ( 40%)
Value ranges after VRP:
_1: ~[0B, 0B]
.MEM_2: VARYING
j_3(D): VARYING
j_7: [0, 255] EQUIVALENCES: { j_3(D) } (1 elements)
f (long unsigned int j)
{
void * _1;
<bb 2> [100.00%]:
if (j_3(D) > 255)
goto <bb 4>; [51.01%]
else
goto <bb 3>; [48.99%]
<bb 3> [48.99%]:
_1 = __builtin_alloca (j_3(D));
foo (_1);
<bb 4> [100.00%]:
return;
}
;; Function f (f, funcdef_no=0, decl_uid=1797, cgraph_uid=0, symbol_order=0)
;; 1 loops found
;;
;; Loop 0
;; header 0, latch 1
;; depth 0, outer -1
;; nodes: 0 1 2 3 4
;; 2 succs { 4 3 }
;; 3 succs { 4 }
;; 4 succs { 1 }
SSA replacement table
N_i -> { O_1 ... O_j } means that N_i replaces O_1, ..., O_j
j_7 -> { j_3(D) }
Incremental SSA update started at block: 2
Number of blocks in CFG: 5
Number of blocks to update: 2 ( 40%)
Value ranges after VRP:
_1: ~[0B, 0B]
.MEM_2: VARYING
j_3(D): VARYING
j_7: [0, 255] EQUIVALENCES: { j_3(D) } (1 elements)
f (long unsigned int j)
{
void * _1;
<bb 2> [100.00%]:
if (j_3(D) > 255)
goto <bb 4>; [51.01%]
else
goto <bb 3>; [48.99%]
<bb 3> [48.99%]:
_1 = __builtin_alloca (j_3(D));
foo (_1);
<bb 4> [100.00%]:
return;
}
More information about the Gcc-bugs
mailing list