* [C PATCH] Fix set_nonincremental_init_from_string (PR c/67410)
@ 2016-08-12 15:55 Jakub Jelinek
2016-08-12 16:02 ` Joseph Myers
2016-08-12 16:04 ` Marek Polacek
0 siblings, 2 replies; 3+ messages in thread
From: Jakub Jelinek @ 2016-08-12 15:55 UTC (permalink / raw)
To: Joseph S. Myers, Marek Polacek; +Cc: gcc-patches
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 <jakub@redhat.com>
Martin Liska <mliska@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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [C PATCH] Fix set_nonincremental_init_from_string (PR c/67410)
2016-08-12 15:55 [C PATCH] Fix set_nonincremental_init_from_string (PR c/67410) Jakub Jelinek
@ 2016-08-12 16:02 ` Joseph Myers
2016-08-12 16:04 ` Marek Polacek
1 sibling, 0 replies; 3+ messages in thread
From: Joseph Myers @ 2016-08-12 16:02 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Marek Polacek, gcc-patches
On Fri, 12 Aug 2016, Jakub Jelinek wrote:
> 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?
OK.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [C PATCH] Fix set_nonincremental_init_from_string (PR c/67410)
2016-08-12 15:55 [C PATCH] Fix set_nonincremental_init_from_string (PR c/67410) Jakub Jelinek
2016-08-12 16:02 ` Joseph Myers
@ 2016-08-12 16:04 ` Marek Polacek
1 sibling, 0 replies; 3+ messages in thread
From: Marek Polacek @ 2016-08-12 16:04 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Joseph S. Myers, gcc-patches
On Fri, Aug 12, 2016 at 05:54:55PM +0200, Jakub Jelinek wrote:
> 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 <jakub@redhat.com>
> Martin Liska <mliska@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.
LGTM.
Marek
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-08-12 16:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-12 15:55 [C PATCH] Fix set_nonincremental_init_from_string (PR c/67410) Jakub Jelinek
2016-08-12 16:02 ` Joseph Myers
2016-08-12 16:04 ` Marek Polacek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).