diff options
author | Tim Lange <mail@tim-lange.me> | 2022-07-22 21:44:07 +0200 |
---|---|---|
committer | Tim Lange <mail@tim-lange.me> | 2022-07-22 21:46:51 +0200 |
commit | b4cc945c045db74f719ab030969806c14e2d5fc3 (patch) | |
tree | e3e3c81f6a94941371c5fa06aedf1e827e9d33fe | |
parent | 64cb87b2381aceaa37230bae7f43c7b9f978d3e3 (diff) | |
download | gcc-b4cc945c045db74f719ab030969806c14e2d5fc3.zip gcc-b4cc945c045db74f719ab030969806c14e2d5fc3.tar.gz gcc-b4cc945c045db74f719ab030969806c14e2d5fc3.tar.bz2 |
Fix handling of zero capacity regions in -Wanalyzer-allocation-size [PR106394]
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.
2022-07-22 Tim Lange <mail@tim-lange.me>
gcc/analyzer/ChangeLog:
PR analyzer/106394
* region-model.cc (capacity_compatible_with_type): Always return true
if alloc_size is zero.
gcc/testsuite/ChangeLog:
PR analyzer/106394
* gcc.dg/analyzer/pr106394.c: New test.
-rw-r--r-- | gcc/analyzer/region-model.cc | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/analyzer/pr106394.c | 19 |
2 files changed, 20 insertions, 1 deletions
diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index 5bb7112..f7df2fc 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 0000000..96bb175 --- /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; +} |