analyzer: fix ICE on setjmp with non-pointer-type [PR97029]
authorDavid Malcolm <dmalcolm@redhat.com>
Sat, 12 Sep 2020 13:28:05 +0000 (09:28 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Mon, 14 Sep 2020 16:26:24 +0000 (12:26 -0400)
gcc/analyzer/ChangeLog:
PR analyzer/97029
* analyzer.cc (is_setjmp_call_p): Require the initial arg to be a
pointer.
* region-model.cc (region_model::deref_rvalue): Assert that the
svalue is of pointer type.

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/pr97029.c: New test.

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

index 814f6248992fffa04aeb9e3495f871b2e31c35d7..82d487858dc66c68725b23b775e0025c7b12a700 100644 (file)
@@ -204,7 +204,9 @@ is_setjmp_call_p (const gcall *call)
 {
   if (is_special_named_call_p (call, "setjmp", 1)
       || is_special_named_call_p (call, "sigsetjmp", 2))
-    return true;
+    /* region_model::on_setjmp requires a pointer.  */
+    if (POINTER_TYPE_P (TREE_TYPE (gimple_call_arg (call, 0))))
+      return true;
 
   return false;
 }
index 75f4eae308319a815756719e62ce96386c2dad2f..d53272e4332c283e5f978556c63ef0b0289518ce 100644 (file)
@@ -1446,6 +1446,7 @@ region_model::region_exists_p (const region *reg) const
 
 /* Get a region for referencing PTR_SVAL, creating a region if need be, and
    potentially generating warnings via CTXT.
+   PTR_SVAL must be of pointer type.
    PTR_TREE if non-NULL can be used when emitting diagnostics.  */
 
 const region *
@@ -1453,6 +1454,7 @@ region_model::deref_rvalue (const svalue *ptr_sval, tree ptr_tree,
                            region_model_context *ctxt)
 {
   gcc_assert (ptr_sval);
+  gcc_assert (POINTER_TYPE_P (ptr_sval->get_type ()));
 
   /* If we're dereferencing PTR_SVAL, assume that it is non-NULL; add this
      as a constraint.  This suppresses false positives from
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr97029.c b/gcc/testsuite/gcc.dg/analyzer/pr97029.c
new file mode 100644 (file)
index 0000000..ff83ad4
--- /dev/null
@@ -0,0 +1,7 @@
+struct vj {};
+
+void
+setjmp (struct vj pl)
+{
+  setjmp (pl);
+}