From b25e5572f1262ed0ec4beea19eec15ac28fdf8ed Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Tue, 6 Feb 2018 13:25:54 +0000 Subject: [PATCH] re PR tree-optimization/84228 (Bogus -Wstringop-truncation warning with -g) PR tree-optimization/84228 * tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Skip debug statements. * c-c++-common/Wstringop-truncation-3.c: New test. From-SVN: r257411 --- gcc/ChangeLog | 5 +++++ gcc/testsuite/ChangeLog | 5 +++++ .../c-c++-common/Wstringop-truncation-3.c | 22 +++++++++++++++++++ gcc/tree-ssa-strlen.c | 2 +- 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/c-c++-common/Wstringop-truncation-3.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b52060946e0..c4d8c959ff5 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2018-02-06 Marek Polacek + + PR tree-optimization/84228 + * tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Skip debug statements. + 2018-02-06 Tamar Christina PR target/82641 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bdec47bb961..e8b123dbb37 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-02-06 Marek Polacek + + PR tree-optimization/84228 + * c-c++-common/Wstringop-truncation-3.c: New test. + 2018-02-06 Tamar Christina PR target/82641 diff --git a/gcc/testsuite/c-c++-common/Wstringop-truncation-3.c b/gcc/testsuite/c-c++-common/Wstringop-truncation-3.c new file mode 100644 index 00000000000..ba6b7de094b --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wstringop-truncation-3.c @@ -0,0 +1,22 @@ +/* PR tree-optimization/84228 */ +/* { dg-do compile } */ +/* { dg-options "-Wstringop-truncation -O2 -g" } */ + +char *strncpy (char *, const char *, __SIZE_TYPE__); +struct S +{ + char arr[64]; +}; + +int +foo (struct S *p1, const char *a) +{ + int b = 5, c = 6, d = 7; + if (a) + goto err; + strncpy (p1->arr, a, sizeof p1->arr); /* { dg-bogus "specified bound" } */ + b = 8; c = 9; d = 10; + p1->arr[3] = '\0'; +err: + return 0; +} diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index c3cf432a921..f0f6535017b 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -1849,7 +1849,7 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt) /* Look for dst[i] = '\0'; after the stxncpy() call and if found avoid the truncation warning. */ - gsi_next (&gsi); + gsi_next_nondebug (&gsi); gimple *next_stmt = gsi_stmt (gsi); if (!gsi_end_p (gsi) && is_gimple_assign (next_stmt)) -- 2.30.2