From 706eb1a70d6f1222cf14e84ab77c8b5404641182 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Mon, 1 May 2017 16:46:49 +0000 Subject: [PATCH] re PR tree-optimization/79715 (hand-rolled strdup with unused result not eliminated) gcc/testsuite/ChangeLog: PR tree-optimization/79715 * gcc.dg/pr79715.c: New test. From-SVN: r247440 --- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr79715.c | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr79715.c diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f1c61a668c5..e0e04f35465 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-05-01 Martin Sebor + + PR tree-optimization/79715 + * gcc.dg/pr79715.c: New test. + 2017-05-01 Tom de Vries PR testsuite/65941 diff --git a/gcc/testsuite/gcc.dg/pr79715.c b/gcc/testsuite/gcc.dg/pr79715.c new file mode 100644 index 00000000000..0f0f90f7122 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr79715.c @@ -0,0 +1,26 @@ +/* PR tree-optimization/79715 - hand-rolled strdup with unused result + not eliminated + { dg-do compile } + { dg-options "-O2 -Wall -fdump-tree-optimized" } */ + +void f (const char *s) +{ + unsigned n = __builtin_strlen (s) + 1; + char *p = __builtin_malloc (n); + __builtin_memcpy (p, s, n); + __builtin_free (p); +} + +void g (const char *s) +{ + unsigned n = __builtin_strlen (s) + 1; + char *p = __builtin_malloc (n); + __builtin_strcpy (p, s); + __builtin_free (p); +} + +/* { dg-final { scan-tree-dump-not "free" "optimized" } } + { dg-final { scan-tree-dump-not "malloc" "optimized" } } + { dg-final { scan-tree-dump-not "memcpy" "optimized" } } + { dg-final { scan-tree-dump-not "strcpy" "optimized" } } + { dg-final { scan-tree-dump-not "strlen" "optimized" } } */ -- 2.30.2