* [PATCH] Fix handling of zero capacity regions in -Wanalyzer-allocation-size [PR106394]
@ 2022-07-22 14:27 Tim Lange
2022-07-22 15:00 ` David Malcolm
0 siblings, 1 reply; 2+ messages in thread
From: Tim Lange @ 2022-07-22 14:27 UTC (permalink / raw)
To: gcc-patches, dmalcolm; +Cc: Tim Lange
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.
---
gcc/analyzer/region-model.cc | 2 +-
gcc/testsuite/gcc.dg/analyzer/pr106394.c | 19 +++++++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr106394.c
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;
+}
--
2.36.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix handling of zero capacity regions in -Wanalyzer-allocation-size [PR106394]
2022-07-22 14:27 [PATCH] Fix handling of zero capacity regions in -Wanalyzer-allocation-size [PR106394] Tim Lange
@ 2022-07-22 15:00 ` David Malcolm
0 siblings, 0 replies; 2+ messages in thread
From: David Malcolm @ 2022-07-22 15:00 UTC (permalink / raw)
To: Tim Lange, gcc-patches
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-07-22 15:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-22 14:27 [PATCH] Fix handling of zero capacity regions in -Wanalyzer-allocation-size [PR106394] Tim Lange
2022-07-22 15:00 ` David Malcolm
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).