From: David Malcolm Date: Thu, 22 Oct 2020 10:15:08 +0000 (-0400) Subject: analyzer: add some C++ test coverage X-Git-Tag: basepoints/gcc-12~4036 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ed7b339c97dffd6f491aeb7052d6601b9d01ae0;p=thirdparty%2Fgcc.git analyzer: add some C++ test coverage 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. --- 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 000000000000..440ac4d0db4b --- /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 000000000000..14acb91ffaa4 --- /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 (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 000000000000..349ab331d38f --- /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 (); +}