public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-6699] analyzer: fix ICE on realloc of zeroed memory [PR104062]
@ 2022-01-18 20:56 David Malcolm
  0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2022-01-18 20:56 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:79e746bb05e432dcd1c18161469272d67c33d79d

commit r12-6699-g79e746bb05e432dcd1c18161469272d67c33d79d
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Tue Jan 18 10:03:53 2022 -0500

    analyzer: fix ICE on realloc of zeroed memory [PR104062]
    
    gcc/analyzer/ChangeLog:
            PR analyzer/104062
            * region-model-manager.cc
            (region_model_manager::maybe_fold_sub_svalue): Avoid casting to
            NULL type when folding access to repeated svalue.
    
    gcc/testsuite/ChangeLog:
            PR analyzer/104062
            * gcc.dg/analyzer/pr104062.c: New test.
    
    Signed-off-by: David Malcolm <dmalcolm@redhat.com>

Diff:
---
 gcc/analyzer/region-model-manager.cc     |  3 ++-
 gcc/testsuite/gcc.dg/analyzer/pr104062.c | 13 +++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/gcc/analyzer/region-model-manager.cc b/gcc/analyzer/region-model-manager.cc
index 903cdfde91d..9d4f5952ef3 100644
--- a/gcc/analyzer/region-model-manager.cc
+++ b/gcc/analyzer/region-model-manager.cc
@@ -794,7 +794,8 @@ region_model_manager::maybe_fold_sub_svalue (tree type,
 
   if (const repeated_svalue *repeated_sval
 	= parent_svalue->dyn_cast_repeated_svalue ())
-    return get_or_create_cast (type, repeated_sval->get_inner_svalue ());
+    if (type)
+      return get_or_create_cast (type, repeated_sval->get_inner_svalue ());
 
   return NULL;
 }
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr104062.c b/gcc/testsuite/gcc.dg/analyzer/pr104062.c
new file mode 100644
index 00000000000..7129c27f60b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/pr104062.c
@@ -0,0 +1,13 @@
+void *
+calloc (__SIZE_TYPE__, __SIZE_TYPE__);
+
+void *
+realloc (void *, __SIZE_TYPE__);
+
+void
+foo (void)
+{
+  int *ap5 = calloc (4, sizeof *ap5);
+  int *ap7 = realloc (ap5, sizeof *ap5);
+} /* { dg-warning "leak of 'ap5'" "leak of ap5" } */
+/* { dg-warning "leak of 'ap7'" "leak of ap7" { target *-*-* } .-1 } */


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-18 20:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-18 20:56 [gcc r12-6699] analyzer: fix ICE on realloc of zeroed memory [PR104062] 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).