Message ID | 20220722142707.178390-1-mail@tim-lange.me |
---|---|
State | New |
Headers | show |
Series | Fix handling of zero capacity regions in -Wanalyzer-allocation-size [PR106394] | expand |
On Fri, 2022-07-22 at 16:27 +0200, Tim Lange wrote: > This patch unifies the handling of zero capacity regions for structs > and other types in the allocation size checker. > Regression-tested on x86_64 Linux. Thanks; looks good for trunk. Dave
diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index 8b7b4e1f697..e01c30407c4 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -2956,7 +2956,7 @@ capacity_compatible_with_type (tree cst, tree pointee_size_tree, unsigned HOST_WIDE_INT alloc_size = TREE_INT_CST_LOW (cst); if (is_struct) - return alloc_size >= pointee_size; + return alloc_size == 0 || alloc_size >= pointee_size; return alloc_size % pointee_size == 0; } diff --git a/gcc/testsuite/gcc.dg/analyzer/pr106394.c b/gcc/testsuite/gcc.dg/analyzer/pr106394.c new file mode 100644 index 00000000000..96bb175fc14 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/pr106394.c @@ -0,0 +1,19 @@ +struct msm_gpu { + // [...snip...] + const struct msm_gpu_perfcntr *perfcntrs; + // [...snip...] +}; + +struct msm_gpu_perfcntr { + // [...snip...] + const char *name; +}; + +static const struct msm_gpu_perfcntr perfcntrs[] = {}; + +struct msm_gpu *test(struct msm_gpu *gpu) { + // [...snip...] + gpu->perfcntrs = perfcntrs; + // [...snip...] + return gpu; +}