On 10/22/21 5:22 AM, Aldy Hernandez wrote:
On Thu, Oct 21, 2021 at 4:51 PM Martin Sebor <mse...@gmail.com> wrote:
I'd like to see gimple-ssa-array-bounds invoked from the access
pass too (instead of from VRP), and eventually -Wrestrict as well.
You can do that right now. The pass has been converted to the new API
and it would just require calling it with a ranger instead of the
vr_values from VRP:
array_bounds_checker array_checker (fun, &vrp_vr_values);
array_checker.check ();
That is, move it where you want and pass it a fresh new gimple_ranger.
If there are any regressions, we'd be glad to look at them.
I appreciate that and I'm not worried about regressions due to
ranger code.
It's not so simple as it seems because of the optimizer
dependencies I mentioned. -Warray-bounds runs before vectorization
and the access pass after it. Moving it into the access pass will
mean dealing with the fallout: either accepting regressions in
the quality of warnings (bad locations due to vectorization
merging distinct stores into one) or running the access pass at
a different point in the pipeline, and facing regressions in
the other warnings due to that. Running it twice, once earlier
for -Warray-bounds and then again later for -Wstringop-overflow
etc, would be less than optimal because they all do the same
thing (compute object sizes and offsets) and should be able to
share the same data (the pointer query cache). So the ideal
solution is to find a middle ground where all these warnings
can run from the same pass with optimal results.
-Warray-bounds might also need to be adjusted for -O0 to avoid
warning on unreachable code, although, surprisingly, that hasn't
been an issue for the other warnings now enabled at -O0.
All this will take some time, which I'm out of for this stage 1.
I'm not sure about the strlen/sprintf warnings; those might need
to stay where they are because they run as part of the optimizers
there.
(By the way, I don't see range info in the access pass at -O0.
Should I?)
I assume you mean you don't see anything in the dump files.
I mean that I don't get accurate range info from the ranger
instance in any function. I'd like the example below to trigger
a warning even at -O0 but it doesn't because n's range is
[0, UINT_MAX] instead of [7, UINT_MAX]:
char a[4];
void f (unsigned n)
{
if (n < 7)
n = 7;
__builtin_memset (a, 0, n);
}
None of the VRP passes (evrp included) run at -O0, so you wouldn't see
anything in the IL. You *may* be able to see some global ranges that
DOM's use of the evrp engine exported, but I'm not sure.
You're going to have to instantiate a gimple_ranger and use it if you
want to have range info available, but that's not going to show up in
the IL, even after you use it, because it doesn't export global ranges
by default. What are you trying to do?
The above. The expected warning runs in the access warning pass.
It uses the per-function instance of the ranger but it gets back
a range for the type. To see that put a breakpoint in
get_size_range() in pointer-query.cc and compile the above with
-O0.
Martin