analyzer: fix ICE on assignment from STRING_CST when building path [PR100011]
authorDavid Malcolm <dmalcolm@redhat.com>
Sat, 10 Apr 2021 20:23:23 +0000 (16:23 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Sat, 10 Apr 2021 20:23:23 +0000 (16:23 -0400)
gcc/analyzer/ChangeLog:
PR analyzer/100011
* region-model.cc (region_model::on_assignment): Avoid NULL
dereference if ctxt is NULL when assigning from a STRING_CST.

gcc/testsuite/ChangeLog:
PR analyzer/100011
* gcc.dg/analyzer/pr100011.c: New test.

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

index 2d3880b..c7038dd 100644 (file)
@@ -726,7 +726,7 @@ region_model::on_assignment (const gassign *assign, region_model_context *ctxt)
           access will "inherit" the individual chars.  */
        const svalue *rhs_sval = get_rvalue (rhs1, ctxt);
        m_store.set_value (m_mgr->get_store_manager(), lhs_reg, rhs_sval,
-                          BK_default, ctxt->get_uncertainty ());
+                          BK_default, ctxt ? ctxt->get_uncertainty () : NULL);
       }
       break;
     }
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr100011.c b/gcc/testsuite/gcc.dg/analyzer/pr100011.c
new file mode 100644 (file)
index 0000000..228cfdf
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-require-effective-target signal } */
+
+#include <stdlib.h>
+#include <signal.h>
+
+void terminate(int sig)
+{
+  char buf[64] = { 0 };
+  exit(1); /* { dg-warning "call to 'exit' from within signal handler" } */
+}
+
+int main(int argc, char **argv)
+{
+  signal(0, terminate); /* { dg-message "registering 'terminate' as signal handler" } */
+  return 0;
+}