Hi,

The following patch fixes PR57385
(http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57385)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 51e7b9e..cca61e7 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2013-05-24  Alexander Ivchenko  <alexander.ivche...@intel.com>
+
+       PR tree-ssa/57385
+       * tree-ssa-sccvn.c (fully_constant_vn_reference_p): Check
+       that index is not negative.
+
 2013-05-23  Richard Henderson  <r...@redhat.com>

        PR target/56742
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b1895fb..730e62f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2013-05-24  Alexander Ivchenko  <alexander.ivche...@intel.com>
+
+       PR tree-ssa/57385
+       * gcc.dg/tree-ssa/pr57385.c: New test.
+
 2013-05-23  Christian Bruel  <christian.br...@st.com>

        PR debug/57351
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr57385.c
b/gcc/testsuite/gcc.dg/tree-ssa/pr57385.c
new file mode 100644
index 0000000..a04a998
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr57385.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O1" } */
+
+int c;
+
+void foo(int f)
+{
+  int wbi=-1;
+  c = (f ? "012346000000000000":"01345:000000006008")[wbi];
+}
diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c
index 49d61b0..0e7a74c 100644
--- a/gcc/tree-ssa-sccvn.c
+++ b/gcc/tree-ssa-sccvn.c
@@ -1294,6 +1294,7 @@ fully_constant_vn_reference_p (vn_reference_t ref)
              == TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0->op0))))
          && GET_MODE_CLASS (TYPE_MODE (op->type)) == MODE_INT
          && GET_MODE_SIZE (TYPE_MODE (op->type)) == 1
+         && tree_int_cst_sgn (op->op0) >= 0
          && compare_tree_int (op->op0, TREE_STRING_LENGTH (arg0->op0)) < 0)
        return build_int_cst_type (op->type,
                                   (TREE_STRING_POINTER (arg0->op0)



 Tested and bootsraped on x86-64 linux.
Is it ok for trunk? If yes, should we backport it to 4.8?


thanks,
Alexander

Reply via email to