analyzer: add some C++ test coverage
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 22 Oct 2020 10:15:08 +0000 (06:15 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Thu, 22 Oct 2020 10:15:08 +0000 (06:15 -0400)
gcc/testsuite/ChangeLog:
* g++.dg/analyzer/ctor-dtor-1.C: New test.
* g++.dg/analyzer/dyncast-1.C: New test.
* g++.dg/analyzer/vfunc-1.C: New test.

gcc/testsuite/g++.dg/analyzer/ctor-dtor-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/analyzer/dyncast-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/analyzer/vfunc-1.C [new file with mode: 0644]

diff --git a/gcc/testsuite/g++.dg/analyzer/ctor-dtor-1.C b/gcc/testsuite/g++.dg/analyzer/ctor-dtor-1.C
new file mode 100644 (file)
index 0000000..440ac4d
--- /dev/null
@@ -0,0 +1,26 @@
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+
+int foo_count;
+
+struct foo
+{
+  foo () __attribute__((noinline))
+  {
+    foo_count++;
+  }  
+  ~foo () __attribute__((noinline))
+  {
+    foo_count--;
+  }
+};
+
+int main ()
+{
+  __analyzer_eval (foo_count == 0); // { dg-warning "TRUE" }
+  {
+    foo f;
+    __analyzer_eval (foo_count == 1); // { dg-warning "TRUE" }
+  }
+  __analyzer_eval (foo_count == 0); // { dg-warning "TRUE" }
+  return 0;
+}
diff --git a/gcc/testsuite/g++.dg/analyzer/dyncast-1.C b/gcc/testsuite/g++.dg/analyzer/dyncast-1.C
new file mode 100644 (file)
index 0000000..14acb91
--- /dev/null
@@ -0,0 +1,21 @@
+#include "../../gcc.dg/analyzer/analyzer-decls.h"
+
+struct base
+{
+  virtual ~base () {}
+};
+struct sub : public base
+{
+  int m_field;
+};
+
+int
+test_1 (base *p)
+{
+  if (sub *q = dynamic_cast <sub*> (p))
+    {
+      __analyzer_dump_path (); // { dg-message "path" }
+      return q->m_field;
+    }
+  return 0;
+}
diff --git a/gcc/testsuite/g++.dg/analyzer/vfunc-1.C b/gcc/testsuite/g++.dg/analyzer/vfunc-1.C
new file mode 100644 (file)
index 0000000..349ab33
--- /dev/null
@@ -0,0 +1,14 @@
+struct base
+{
+  virtual int fn () const;
+};
+struct sub : public base
+{
+  int fn () const;
+};
+
+int
+test_1 (base *p)
+{
+  return p->fn ();
+}