analyzer: fix ICE on dtor [PR97489]
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 22 Oct 2020 10:12:31 +0000 (06:12 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Thu, 22 Oct 2020 10:12:31 +0000 (06:12 -0400)
gcc/analyzer/ChangeLog:
PR analyzer/97489
* engine.cc (exploded_graph::add_function_entry): Assert that we
have a function body.
(exploded_graph::on_escaped_function): Reject fndecls that don't
have a function body.

gcc/testsuite/ChangeLog:
PR analyzer/97489
* g++.dg/analyzer/pr97489.C: New test.

gcc/analyzer/engine.cc
gcc/testsuite/g++.dg/analyzer/pr97489.C [new file with mode: 0644]

index 65d7495f26f546ba577d98f8210f9640298310f8..b1c877e52315e318f3d5c96b6b10deaa828b6693 100644 (file)
@@ -1937,6 +1937,8 @@ exploded_graph::~exploded_graph ()
 exploded_node *
 exploded_graph::add_function_entry (function *fun)
 {
+  gcc_assert (gimple_has_body_p (fun->decl));
+
   /* Be idempotent.  */
   if (m_functions_with_enodes.contains (fun))
     {
@@ -3982,6 +3984,9 @@ exploded_graph::on_escaped_function (tree fndecl)
   if (!fun)
     return;
 
+  if (!gimple_has_body_p (fndecl))
+    return;
+
   exploded_node *enode = add_function_entry (fun);
   if (logger)
     {
diff --git a/gcc/testsuite/g++.dg/analyzer/pr97489.C b/gcc/testsuite/g++.dg/analyzer/pr97489.C
new file mode 100644 (file)
index 0000000..9322e72
--- /dev/null
@@ -0,0 +1,6 @@
+struct X {
+  virtual ~X() {}
+  virtual void key_function();
+};
+
+void X::key_function() {}