From 86a120d362180f4211055d0f74461e931bd0116f Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Tue, 9 Jul 2019 14:43:38 -0400 Subject: [PATCH 69/85] FIXME: paths-7.c --- gcc/testsuite/gcc.dg/analyzer/paths-7.c | 60 +++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/analyzer/paths-7.c diff --git a/gcc/testsuite/gcc.dg/analyzer/paths-7.c b/gcc/testsuite/gcc.dg/analyzer/paths-7.c new file mode 100644 index 0000000..d13eacf --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/paths-7.c @@ -0,0 +1,60 @@ +/* { dg-additional-options "-fanalyzer-state-merge" } */ + +#include + +extern int foo (int); + +int test (int flag, void *ptr, int *p, int n) +{ + int result; + int sum = 0; + int i; + + __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 exploded node" } */ + + if (flag) + free (ptr); + + __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 exploded nodes" } */ + + for (i = 0; i < n; i++) + p[i] = i; + for (i = 0; i < n; i++) + sum += foo (p[i]); /* { dg-bogus "uninitialized" } */ + result = sum; + + __analyzer_dump_exploded_nodes (0); /* { dg-warning "3 exploded nodes" } */ + // FIXME: why 3 here? + + if (flag) + free (ptr); /* { dg-warning "double-free of 'ptr'" } */ + return result; +} + +int test_2 (int flag, int *p, int n) +{ + int result; + int sum = 0; + int i; + + void *ptr = malloc (16); + + __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 exploded node" } */ + + if (flag) + free (ptr); + + __analyzer_dump_exploded_nodes (0); /* { dg-warning "2 exploded nodes" } */ + + for (i = 0; i < n; i++) + p[i] = i; + for (i = 0; i < n; i++) + sum += foo (p[i]); /* { dg-bogus "uninitialized" } */ + result = sum; + + __analyzer_dump_exploded_nodes (0); /* { dg-warning "5 exploded nodes" } */ + // FIXME: why 5 here? + + free (ptr); /* { dg-warning "double-free of 'ptr'" } */ + return result; +} -- 1.8.5.3