commit:     3e95a56d5d25f40b0f7cad7801714fe797037fb1
Author:     Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
AuthorDate: Sun Oct 21 09:22:51 2018 +0000
Commit:     Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
CommitDate: Sun Oct 21 09:22:51 2018 +0000
URL:        https://gitweb.gentoo.org/proj/gcc-patches.git/commit/?id=3e95a56d

8.2.0: fix ICE on strncmp validation

Reported-by: Toralf Förster
https://bugs.gentoo.org/668044
https://gcc.gnu.org/PR87099
Signed-off-by: Sergei Trofimovich <slyfox <AT> gentoo.org>

 8.2.0/gentoo/113_all_ICE-on-strncmp-PR87099.patch | 86 +++++++++++++++++++++++
 8.2.0/gentoo/README.history                       |  1 +
 2 files changed, 87 insertions(+)

diff --git a/8.2.0/gentoo/113_all_ICE-on-strncmp-PR87099.patch 
b/8.2.0/gentoo/113_all_ICE-on-strncmp-PR87099.patch
new file mode 100644
index 0000000..7e37b5e
--- /dev/null
+++ b/8.2.0/gentoo/113_all_ICE-on-strncmp-PR87099.patch
@@ -0,0 +1,86 @@
+https://bugs.gentoo.org/668044
+https://gcc.gnu.org/PR87099
+
+From e24ceb4802f0cc1bb9e498af6f5bdd29e556c34b Mon Sep 17 00:00:00 2001
+From: jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
+Date: Tue, 28 Aug 2018 11:43:22 +0000
+Subject: [PATCH]       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.     Only use lenrng[1] if non-NULL and
+ INTEGER_CST.  Don't uselessly         increment lenrng[0].
+
+       * gcc.dg/pr87099.c: New test.
+
+
+git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-8-branch@263917 
138bc75d-0d04-0410-961f-82ee72b054a4
+---
+ gcc/calls.c                    | 12 ++++++++----
+ gcc/testsuite/gcc.dg/pr87099.c | 21 +++++++++++++++++++++
+ 4 files changed, 43 insertions(+), 4 deletions(-)
+ create mode 100644 gcc/testsuite/gcc.dg/pr87099.c
+
+--- a/gcc/calls.c
++++ b/gcc/calls.c
+@@ -1627,6 +1627,9 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp)
+   if (!fndecl || DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL)
+     return;
+ 
++  if (!warn_stringop_overflow)
++    return;
++
+   bool with_bounds = CALL_WITH_BOUNDS_P (exp);
+ 
+   unsigned nargs = call_expr_nargs (exp);
+@@ -1655,7 +1658,10 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp)
+          conservatively as the bound for the unbounded function,
+          and to adjust the range of the bound of the bounded ones.  */
+       unsigned stride = with_bounds ? 2 : 1;
+-      for (unsigned argno = 0; argno < nargs && !*lenrng; argno += stride)
++      for (unsigned argno = 0;
++           argno < MIN (nargs, 2 * stride)
++           && !(lenrng[1] && TREE_CODE (lenrng[1]) == INTEGER_CST);
++           argno += stride)
+         {
+           tree arg = CALL_EXPR_ARG (exp, argno);
+           if (!get_attr_nonstring_decl (arg))
+@@ -1693,11 +1699,9 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp)
+   if (bound)
+     get_size_range (bound, bndrng);
+ 
+-  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);
+ 
+--- /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);
++}
+-- 
+2.19.1
+

diff --git a/8.2.0/gentoo/README.history b/8.2.0/gentoo/README.history
index c046242..6b549db 100644
--- a/8.2.0/gentoo/README.history
+++ b/8.2.0/gentoo/README.history
@@ -2,6 +2,7 @@
        + 111_all_ubd-hog-PR85704.patch
        U 105_all_libgfortran-Werror.patch
        + 112_all_libstdcxx-no-vtv.patch
+       + 113_all_ICE-on-strncmp-PR87099.patch
 
 1.4            01 Oct 2018
        + 105_all_libgfortran-Werror.patch

Reply via email to