From: Jakub Jelinek Date: Tue, 28 Aug 2018 11:13:04 +0000 (+0200) Subject: re PR middle-end/87099 (internal compiler error: segmentation fault) X-Git-Tag: upstream/12.2.0~29530 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2c8861b7505cdc04377cd125565bb5ccadb29529;p=platform%2Fupstream%2Fgcc.git re PR middle-end/87099 (internal compiler error: segmentation fault) PR middle-end/87099 * calls.c (maybe_warn_nonstring_arg): Punt early if warn_stringop_overflow is zero. Don't call get_range_strlen on 3rd argument, keep iterating until lenrng[1] is INTEGER_CST. Swap comparison operands to have constants on rhs. Only use lenrng[1] if non-NULL and INTEGER_CST. Don't uselessly increment lenrng[0]. * gcc.dg/pr87099.c: New test. From-SVN: r263915 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0e2f9d0..66396a0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2018-08-28 Jakub Jelinek + + PR middle-end/87099 + * calls.c (maybe_warn_nonstring_arg): Punt early if + warn_stringop_overflow is zero. Don't call get_range_strlen + on 3rd argument, keep iterating until lenrng[1] is INTEGER_CST. + Swap comparison operands to have constants on rhs. Only use + lenrng[1] if non-NULL and INTEGER_CST. Don't uselessly + increment lenrng[0]. + 2018-08-28 Richard Sandiford * tree-ssa-sccvn.c (fully_constant_vn_reference_p): Fix unguarded diff --git a/gcc/calls.c b/gcc/calls.c index f57ecf9..87e3f00 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -1545,7 +1545,7 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp) if (!fndecl || !fndecl_built_in_p (fndecl, BUILT_IN_NORMAL)) return; - if (TREE_NO_WARNING (exp)) + if (TREE_NO_WARNING (exp) || !warn_stringop_overflow) return; unsigned nargs = call_expr_nargs (exp); @@ -1573,7 +1573,9 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp) the range of their known or possible lengths and use it conservatively as the bound for the unbounded function, and to adjust the range of the bound of the bounded ones. */ - for (unsigned argno = 0; argno < nargs && !*lenrng; argno ++) + for (unsigned argno = 0; + argno < MIN (nargs, 2) + && !(lenrng[1] && TREE_CODE (lenrng[1]) == INTEGER_CST); argno++) { tree arg = CALL_EXPR_ARG (exp, argno); if (!get_attr_nonstring_decl (arg)) @@ -1585,12 +1587,12 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp) case BUILT_IN_STRNCAT: case BUILT_IN_STPNCPY: case BUILT_IN_STRNCPY: - if (2 < nargs) + if (nargs > 2) bound = CALL_EXPR_ARG (exp, 2); break; case BUILT_IN_STRNDUP: - if (1 < nargs) + if (nargs > 1) bound = CALL_EXPR_ARG (exp, 1); break; @@ -1600,7 +1602,7 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp) if (!get_attr_nonstring_decl (arg)) get_range_strlen (arg, lenrng); - if (1 < nargs) + if (nargs > 1) bound = CALL_EXPR_ARG (exp, 1); break; } @@ -1640,11 +1642,9 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp) } } - if (*lenrng) + if (lenrng[1] && TREE_CODE (lenrng[1]) == INTEGER_CST) { /* Add one for the nul. */ - lenrng[0] = const_binop (PLUS_EXPR, TREE_TYPE (lenrng[0]), - lenrng[0], size_one_node); lenrng[1] = const_binop (PLUS_EXPR, TREE_TYPE (lenrng[1]), lenrng[1], size_one_node); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5dea5f7..c621049 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-08-28 Jakub Jelinek + + PR middle-end/87099 + * gcc.dg/pr87099.c: New test. + 2018-08-28 Richard Sandiford PR testsuite/87078 diff --git a/gcc/testsuite/gcc.dg/pr87099.c b/gcc/testsuite/gcc.dg/pr87099.c new file mode 100644 index 0000000..599d721 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr87099.c @@ -0,0 +1,21 @@ +/* PR middle-end/87099 */ +/* { dg-do compile } */ +/* { dg-options "-Wstringop-overflow" } */ + +void bar (char *); + +int +foo (int n) +{ + char v[n]; + bar (v); + return __builtin_strncmp (&v[1], "aaa", 3); +} + +int +baz (int n, char *s) +{ + char v[n]; + bar (v); + return __builtin_strncmp (&v[1], s, 3); +}