public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] analyzer: add some C++ test coverage
@ 2020-10-22 10:22 David Malcolm
  0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2020-10-22 10:22 UTC (permalink / raw)
  To: gcc-patches

Successfully regrtested on x86_64-pc-linux-gnu.
Pushed to master as 9ed7b339c97dffd6f491aeb7052d6601b9d01ae0.

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 | 26 +++++++++++++++++++++
 gcc/testsuite/g++.dg/analyzer/dyncast-1.C   | 21 +++++++++++++++++
 gcc/testsuite/g++.dg/analyzer/vfunc-1.C     | 14 +++++++++++
 3 files changed, 61 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/analyzer/ctor-dtor-1.C
 create mode 100644 gcc/testsuite/g++.dg/analyzer/dyncast-1.C
 create mode 100644 gcc/testsuite/g++.dg/analyzer/vfunc-1.C

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
index 00000000000..440ac4d0db4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/analyzer/ctor-dtor-1.C
@@ -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
index 00000000000..14acb91ffaa
--- /dev/null
+++ b/gcc/testsuite/g++.dg/analyzer/dyncast-1.C
@@ -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
index 00000000000..349ab331d38
--- /dev/null
+++ b/gcc/testsuite/g++.dg/analyzer/vfunc-1.C
@@ -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 ();
+}
-- 
2.26.2


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-10-22 10:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-22 10:22 [committed] analyzer: add some C++ test coverage David Malcolm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).