Hi!

The wide-int conversion of set_nonincremental_init_from_string broke this
function.
Before we used val[bitpos < HOST_BITS_PER_WIDE_INT], but val[1] and val[0]
has been swapped, so either it should be bitpos >= HOST_BITS_PER_WIDE_INT,
or bitpos / HOST_BITS_PER_WIDE_INT.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/6.2?

2016-08-12  Jakub Jelinek  <ja...@redhat.com>
            Martin Liska  <mli...@suse.cz>

        PR c/67410
        * c-typeck.c (set_nonincremental_init_from_string): Use / instead of
        % to determine val element to change.  Assert that
        wchar_bytes * charwidth fits into val array.

        * gcc.dg/pr67410.c: New test.

--- gcc/c/c-typeck.c.jj 2016-08-06 12:11:47.000000000 +0200
+++ gcc/c/c-typeck.c    2016-08-12 15:18:40.629878806 +0200
@@ -8558,6 +8558,8 @@ set_nonincremental_init_from_string (tre
 
   wchar_bytes = TYPE_PRECISION (TREE_TYPE (TREE_TYPE (str))) / BITS_PER_UNIT;
   charwidth = TYPE_PRECISION (char_type_node);
+  gcc_assert ((size_t) wchar_bytes * charwidth
+             <= ARRAY_SIZE (val) * HOST_BITS_PER_WIDE_INT);
   type = TREE_TYPE (constructor_type);
   p = TREE_STRING_POINTER (str);
   end = p + TREE_STRING_LENGTH (str);
@@ -8583,7 +8585,7 @@ set_nonincremental_init_from_string (tre
                bitpos = (wchar_bytes - byte - 1) * charwidth;
              else
                bitpos = byte * charwidth;
-             val[bitpos % HOST_BITS_PER_WIDE_INT]
+             val[bitpos / HOST_BITS_PER_WIDE_INT]
                |= ((unsigned HOST_WIDE_INT) ((unsigned char) *p++))
                   << (bitpos % HOST_BITS_PER_WIDE_INT);
            }
--- gcc/testsuite/gcc.dg/pr67410.c.jj   2016-08-12 14:58:19.643334006 +0200
+++ gcc/testsuite/gcc.dg/pr67410.c      2016-08-12 15:02:06.391451195 +0200
@@ -0,0 +1,15 @@
+/* PR c/67410 */
+/* { dg-do run } */
+/* { dg-options "-std=gnu11" } */
+
+struct {
+  __CHAR16_TYPE__ s[2];
+} a[] = { u"ff", [0].s[0] = u'x', [1] = u"\u1234\u4567", [1].s[0] = u'\u89ab' 
};
+
+int
+main ()
+{
+  if (a[0].s[0] != u'x' || a[0].s[1] != u'f' || a[1].s[0] != u'\u89ab' || 
a[1].s[1] != u'\u4567')
+    __builtin_abort ();
+  return 0;
+}

        Jakub

Reply via email to