diff options
author | Richard Biener <rguenther@suse.de> | 2023-03-17 13:14:49 +0100 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2023-03-21 09:21:29 +0100 |
commit | 5f413dc41ee4f8bc3a0fc295f98b75dceae52fa8 (patch) | |
tree | abe9fce7572f5c71e9c9a82faa0bb469054d9574 /gcc/value-range.h | |
parent | 259bd768640328cc98647c5cf8b0d6dcfba6d4bf (diff) | |
download | gcc-5f413dc41ee4f8bc3a0fc295f98b75dceae52fa8.zip gcc-5f413dc41ee4f8bc3a0fc295f98b75dceae52fa8.tar.gz gcc-5f413dc41ee4f8bc3a0fc295f98b75dceae52fa8.tar.bz2 |
tree-optimization/109170 - bogus use-after-free with __builtin_expect
The following adds a missing range-op for __builtin_expect which
helps -Wuse-after-free to detect the case a realloc original
pointer is used when the result was NULL. The implementation
should handle all argument one pass-through builtins we handle
in the fnspec machinery, but that's defered to GCC 14.
The gcc.dg/tree-ssa/ssa-lim-21.c testcase needs adjustment because
for (int j = 0; j < m; j++)
if (__builtin_expect (m, 0))
for (int i = 0; i < m; i++)
is now correctly optimized to a unconditional jump by EVRP - m
cannot be zero when the outer loop is entered. I've adjusted
the outer loop to iterate 'n' times which makes us apply store-motion
to 'count' and 'q->data1' but only out of the inner loop and
as expected not apply store motion to 'q->data' at all.
The gcc.dg/predict-20.c testcase relies on broken behavior of
profile estimation when trying to handle __builtin_expect values
flowing into PHI nodes. I have opened PR109210 and removed
the expected matching from the testcase.
PR tree-optimization/109170
* gimple-range-op.cc (cfn_pass_through_arg1): New.
(gimple_range_op_handler::maybe_builtin_call): Handle
__builtin_expect via cfn_pass_through_arg1.
* gcc.dg/Wuse-after-free-pr109170.c: New testcase.
* gcc.dg/tree-ssa/ssa-lim-21.c: Adjust.
* gcc.dg/predict-20.c: Likewise.
Diffstat (limited to 'gcc/value-range.h')
0 files changed, 0 insertions, 0 deletions