analyzer: fix ICE on NULL dereference [PR96644]
authorDavid Malcolm <dmalcolm@redhat.com>
Mon, 17 Aug 2020 16:30:56 +0000 (12:30 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Mon, 17 Aug 2020 18:47:18 +0000 (14:47 -0400)
gcc/analyzer/ChangeLog:
PR analyzer/96644
* region-model-manager.cc (get_region_for_unexpected_tree_code):
Handle ctxt being NULL.

gcc/testsuite/ChangeLog:
PR analyzer/96644
* gcc.dg/analyzer/pr96644.c: New test.

gcc/analyzer/region-model-manager.cc
gcc/testsuite/gcc.dg/analyzer/pr96644.c [new file with mode: 0644]

index 9c7b0602e88cac5fc10c25281d1af557911f6cb7..4faeaa52a639aee5662668d5292fad26fb6c13a2 100644 (file)
@@ -927,11 +927,11 @@ get_region_for_unexpected_tree_code (region_model_context *ctxt,
                                     tree t,
                                     const dump_location_t &loc)
 {
-  gcc_assert (ctxt);
   tree type = TYPE_P (t) ? t : TREE_TYPE (t);
   region *new_reg
     = new unknown_region (alloc_region_id (), &m_root_region, type);
-  ctxt->on_unexpected_tree_code (t, loc);
+  if (ctxt)
+    ctxt->on_unexpected_tree_code (t, loc);
   return new_reg;
 }
 
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr96644.c b/gcc/testsuite/gcc.dg/analyzer/pr96644.c
new file mode 100644 (file)
index 0000000..3953c8d
--- /dev/null
@@ -0,0 +1,24 @@
+/* { dg-additional-options "-O1" } */
+
+int oh[1];
+int *x3;
+
+int *
+cm (char *m0)
+{
+  return oh;
+}
+
+void
+ek (void)
+{
+  for (;;)
+    {
+      char *b2 = 0;
+
+      if (*b2 != 0) /* { dg-warning "dereference of NULL" } */
+       ++b2;
+
+      x3 = cm (b2);
+    }
+}