gcc/testsuite/ChangeLog: * gcc.dg/analyzer/malloc-ipa-8-lto-a.c: New test. * gcc.dg/analyzer/malloc-ipa-8-lto-b.c: New test. * gcc.dg/analyzer/malloc-ipa-8-lto-c.c: New test. * gcc.dg/analyzer/malloc-ipa-8-lto.h: New test. --- gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-a.c | 12 ++++++++++++ gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-b.c | 18 ++++++++++++++++++ gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-c.c | 17 +++++++++++++++++ gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto.h | 12 ++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-a.c create mode 100644 gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-b.c create mode 100644 gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-c.c create mode 100644 gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto.h
diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-a.c b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-a.c new file mode 100644 index 0000000..c34e4be --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-a.c @@ -0,0 +1,12 @@ +#include <stdlib.h> +#include "malloc-ipa-8-lto.h" + +void *wrapped_malloc (size_t size) +{ + return malloc (size); +} + +void wrapped_free (void *ptr) +{ + free (ptr); +} diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-b.c b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-b.c new file mode 100644 index 0000000..c9d7df1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-b.c @@ -0,0 +1,18 @@ +#include <stdlib.h> +#include "malloc-ipa-8-lto.h" + +boxed_int * +make_boxed_int (int i) +{ + boxed_int *result = (boxed_int *)wrapped_malloc (sizeof (boxed_int)); + if (!result) + abort (); + result->i = i; + return result; +} + +void +free_boxed_int (boxed_int *bi) +{ + wrapped_free (bi); +} diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-c.c b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-c.c new file mode 100644 index 0000000..d332db1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto-c.c @@ -0,0 +1,17 @@ +/* { dg-do link } */ +/* { dg-require-effective-target lto } */ +/* { dg-additional-options "-flto" } */ +/* { dg-additional-sources "malloc-ipa-8-lto-a.c malloc-ipa-8-lto-b.c" } */ + +#include <stdlib.h> +#include "malloc-ipa-8-lto.h" + +void test (int i) +{ + boxed_int *obj = make_boxed_int (i); + + free_boxed_int (obj); + free (obj); /* { dg-warning "double-free" } */ +} + +int main() { return 0; } diff --git a/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto.h b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto.h new file mode 100644 index 0000000..f24eefc --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/malloc-ipa-8-lto.h @@ -0,0 +1,12 @@ +#include <stddef.h> + +extern void *wrapped_malloc (size_t size); +extern void wrapped_free (void *ptr); + +typedef struct boxed_int +{ + int i; +} boxed_int; + +extern boxed_int *make_boxed_int (int i); +extern void free_boxed_int (boxed_int *bi); -- 1.8.5.3