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.
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;
}
--- /dev/null
+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;
+}