Message ID | 20200123021632.12466-1-dmalcolm@redhat.com |
---|---|
State | New |
Headers | show |
Series | analyzer: testsuite: introduce analyzer-torture.exp | expand |
David Malcolm <dmalcolm@redhat.com> writes: > Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. > > OK for master? I'm working on various followup bugfixes that could > use this for test coverage. > > gcc/testsuite/ChangeLog: > * gcc.dg/analyzer/data-model-3.c: Remove hardcoded "-O2" and move > to torture/conftest-1.c. > * gcc.dg/analyzer/torture/analyzer-torture.exp: New. > * gcc.dg/analyzer/torture/conftest-1.c: Move here from > analyzer/data-model-3.c. > * gcc.dg/analyzer/torture/poc.c: New test. OK, thanks. Richard > --- > gcc/testsuite/gcc.dg/analyzer/data-model-3.c | 15 ------- > .../analyzer/torture/analyzer-torture.exp | 44 +++++++++++++++++++ > .../gcc.dg/analyzer/torture/conftest-1.c | 10 +++++ > gcc/testsuite/gcc.dg/analyzer/torture/poc.c | 24 ++++++++++ > 4 files changed, 78 insertions(+), 15 deletions(-) > delete mode 100644 gcc/testsuite/gcc.dg/analyzer/data-model-3.c > create mode 100644 gcc/testsuite/gcc.dg/analyzer/torture/analyzer-torture.exp > create mode 100644 gcc/testsuite/gcc.dg/analyzer/torture/conftest-1.c > create mode 100644 gcc/testsuite/gcc.dg/analyzer/torture/poc.c > > diff --git a/gcc/testsuite/gcc.dg/analyzer/data-model-3.c b/gcc/testsuite/gcc.dg/analyzer/data-model-3.c > deleted file mode 100644 > index 3d572eb8d73..00000000000 > --- a/gcc/testsuite/gcc.dg/analyzer/data-model-3.c > +++ /dev/null > @@ -1,15 +0,0 @@ > -/* { dg-additional-options "-O2" } */ > -/* TODO:is there a way to automatically run the tests on various > - optimizations levels, and with/without debuginfo, rather than > - hardcoding options? Adapt from torture .exp, presumably. */ > - > -#include <stdio.h> > -int > -main () > -{ > - FILE *f = fopen ("conftest.out", "w"); > - return ferror (f) || fclose (f) != 0; > - > - ; > - return 0; > -} > diff --git a/gcc/testsuite/gcc.dg/analyzer/torture/analyzer-torture.exp b/gcc/testsuite/gcc.dg/analyzer/torture/analyzer-torture.exp > new file mode 100644 > index 00000000000..a4d98bb2297 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/analyzer/torture/analyzer-torture.exp > @@ -0,0 +1,44 @@ > +# Copyright (C) 2020 Free Software Foundation, Inc. > + > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with GCC; see the file COPYING3. If not see > +# <http://www.gnu.org/licenses/>. > + > +# This harness is for tests that should be run at all optimisation levels. > + > +load_lib gcc-dg.exp > + > +# If the analyzer has not been enabled, bail. > +if { ![check_effective_target_analyzer] } { > + return > +} > + > +dg-init > + > +global DEFAULT_CFLAGS > +if [info exists DEFAULT_CFLAGS] then { > + set save_default_cflags $DEFAULT_CFLAGS > +} > + > +# If a testcase doesn't have special options, use these. > +set DEFAULT_CFLAGS "-fanalyzer -fdiagnostics-path-format=separate-events -Wanalyzer-too-complex -fanalyzer-call-summaries" > + > +gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.c]] "" $DEFAULT_CFLAGS > + > +dg-finish > + > +if [info exists save_default_cflags] { > + set DEFAULT_CFLAGS $save_default_cflags > +} else { > + unset DEFAULT_CFLAGS > +} > diff --git a/gcc/testsuite/gcc.dg/analyzer/torture/conftest-1.c b/gcc/testsuite/gcc.dg/analyzer/torture/conftest-1.c > new file mode 100644 > index 00000000000..0cf85f0ebe1 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/analyzer/torture/conftest-1.c > @@ -0,0 +1,10 @@ > +#include <stdio.h> > +int > +main () > +{ > + FILE *f = fopen ("conftest.out", "w"); > + return ferror (f) || fclose (f) != 0; > + > + ; > + return 0; > +} > diff --git a/gcc/testsuite/gcc.dg/analyzer/torture/poc.c b/gcc/testsuite/gcc.dg/analyzer/torture/poc.c > new file mode 100644 > index 00000000000..1ad45b2f63e > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/analyzer/torture/poc.c > @@ -0,0 +1,24 @@ > +/* { dg-do link } */ > + > +#include <stdlib.h> > + > +void test_1 (void *ptr) > +{ > + free (ptr); > + free (ptr); /* { dg-warning "double-free" } */ > +} > + > +struct s > +{ > + void *ptr; > +}; > + > +void test_2 (struct s *x) > +{ > + free (x->ptr); > + free (x->ptr); /* { dg-warning "double-free" } */ > +} > + > +/* TODO: be more precise about what is freed. */ > + > +int main () {}
diff --git a/gcc/testsuite/gcc.dg/analyzer/data-model-3.c b/gcc/testsuite/gcc.dg/analyzer/data-model-3.c deleted file mode 100644 index 3d572eb8d73..00000000000 --- a/gcc/testsuite/gcc.dg/analyzer/data-model-3.c +++ /dev/null @@ -1,15 +0,0 @@ -/* { dg-additional-options "-O2" } */ -/* TODO:is there a way to automatically run the tests on various - optimizations levels, and with/without debuginfo, rather than - hardcoding options? Adapt from torture .exp, presumably. */ - -#include <stdio.h> -int -main () -{ - FILE *f = fopen ("conftest.out", "w"); - return ferror (f) || fclose (f) != 0; - - ; - return 0; -} diff --git a/gcc/testsuite/gcc.dg/analyzer/torture/analyzer-torture.exp b/gcc/testsuite/gcc.dg/analyzer/torture/analyzer-torture.exp new file mode 100644 index 00000000000..a4d98bb2297 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/torture/analyzer-torture.exp @@ -0,0 +1,44 @@ +# Copyright (C) 2020 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# <http://www.gnu.org/licenses/>. + +# This harness is for tests that should be run at all optimisation levels. + +load_lib gcc-dg.exp + +# If the analyzer has not been enabled, bail. +if { ![check_effective_target_analyzer] } { + return +} + +dg-init + +global DEFAULT_CFLAGS +if [info exists DEFAULT_CFLAGS] then { + set save_default_cflags $DEFAULT_CFLAGS +} + +# If a testcase doesn't have special options, use these. +set DEFAULT_CFLAGS "-fanalyzer -fdiagnostics-path-format=separate-events -Wanalyzer-too-complex -fanalyzer-call-summaries" + +gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.c]] "" $DEFAULT_CFLAGS + +dg-finish + +if [info exists save_default_cflags] { + set DEFAULT_CFLAGS $save_default_cflags +} else { + unset DEFAULT_CFLAGS +} diff --git a/gcc/testsuite/gcc.dg/analyzer/torture/conftest-1.c b/gcc/testsuite/gcc.dg/analyzer/torture/conftest-1.c new file mode 100644 index 00000000000..0cf85f0ebe1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/torture/conftest-1.c @@ -0,0 +1,10 @@ +#include <stdio.h> +int +main () +{ + FILE *f = fopen ("conftest.out", "w"); + return ferror (f) || fclose (f) != 0; + + ; + return 0; +} diff --git a/gcc/testsuite/gcc.dg/analyzer/torture/poc.c b/gcc/testsuite/gcc.dg/analyzer/torture/poc.c new file mode 100644 index 00000000000..1ad45b2f63e --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/torture/poc.c @@ -0,0 +1,24 @@ +/* { dg-do link } */ + +#include <stdlib.h> + +void test_1 (void *ptr) +{ + free (ptr); + free (ptr); /* { dg-warning "double-free" } */ +} + +struct s +{ + void *ptr; +}; + +void test_2 (struct s *x) +{ + free (x->ptr); + free (x->ptr); /* { dg-warning "double-free" } */ +} + +/* TODO: be more precise about what is freed. */ + +int main () {}