From: Marek Polacek Date: Thu, 8 Feb 2018 16:18:04 +0000 (+0000) Subject: re PR tree-optimization/84238 (ICE tree check: expected integer_cst, have plus_expr... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c6ba596b58e458391ed015e26b763e72ec725600;p=gcc.git re PR tree-optimization/84238 (ICE tree check: expected integer_cst, have plus_expr in to_wide, at tree.h:5527) PR tree-optimization/84238 * tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Verify the result of get_range_strlen. * gcc.dg/Wstringop-overflow-3.c: New test. From-SVN: r257497 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d9c45c9e794..461656b1fa0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-02-08 Marek Polacek + + PR tree-optimization/84238 + * tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Verify the result of + get_range_strlen. + 2018-02-08 Richard Sandiford PR tree-optimization/84265 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6d451959f12..92e9e34ae07 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-02-08 Marek Polacek + + PR tree-optimization/84238 + * gcc.dg/Wstringop-overflow-3.c: New test. + 2018-02-08 Nathan Sidwell * g++.dg/cpp0x/initlist93.C: Adjust diagnostic. diff --git a/gcc/testsuite/gcc.dg/Wstringop-overflow-3.c b/gcc/testsuite/gcc.dg/Wstringop-overflow-3.c new file mode 100644 index 00000000000..590184461a9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wstringop-overflow-3.c @@ -0,0 +1,13 @@ +/* PR tree-optimization/84238 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +char a[1]; +int b; +char *strncpy (char *, char *, __SIZE_TYPE__); +void +c () +{ + char d[b]; + strncpy (a, &d[3], 3); /* { dg-warning "writing 3 bytes into a region of size 1" } */ +} diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index f0f6535017b..94ed2bedc03 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -1899,7 +1899,10 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt) { tree range[2]; get_range_strlen (src, range); - if (range[0]) + if (range[0] != NULL_TREE + && TREE_CODE (range[0]) == INTEGER_CST + && range[1] != NULL_TREE + && TREE_CODE (range[1]) == INTEGER_CST) { lenrange[0] = wi::to_wide (range[0], prec); lenrange[1] = wi::to_wide (range[1], prec);