From patchwork Fri Aug 12 15:54:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 658693 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3s9qGb55QPz9sBr for ; Sat, 13 Aug 2016 01:55:18 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=yOTSvmdq; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=VR/EjfzU3dOrAa8Ar5JGlg29ALxkg Z7T+UkeF4aOdvghfrfCwjVCCvAB4aI4hHelfNIBVDvjRq847oWHJ9aqV4XJdWF7p kwDcy9x/TqnwrcnX4YwbTYsqlp0t7/l/JiTiyIP5PVcnOC8NB9CwfugRNVGvgQuI SC3NDi+KyDuonc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=MipQMjOCGoYZpmh3hBAfWUJCriU=; b=yOT SvmdqV7DXv58YaKnTCyrfQEnZ/Me5hbXB0ZPFsJcC/CAhRjqYfStbbZA/sPnuvj1 H53BEH4HHImtPO/YQvsk81l5RC+CV2oyEhjHKsjwhd9MLMo4zfDIMdOFKum/F4/A 7ttk3wjUQm6wE/cXfx0LO8nKVOVQj4ZVWEPox/Fw= Received: (qmail 29903 invoked by alias); 12 Aug 2016 15:55:11 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 29870 invoked by uid 89); 12 Aug 2016 15:55:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=swapped, array_size, sk:TREE_ST, sk:tree_st X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 12 Aug 2016 15:55:01 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B58624E330; Fri, 12 Aug 2016 15:54:59 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-204-43.brq.redhat.com [10.40.204.43]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7CFsvCo017438 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 12 Aug 2016 11:54:59 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id u7CFsu3W006304; Fri, 12 Aug 2016 17:54:57 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id u7CFstCE006303; Fri, 12 Aug 2016 17:54:55 +0200 Date: Fri, 12 Aug 2016 17:54:55 +0200 From: Jakub Jelinek To: "Joseph S. Myers" , Marek Polacek Cc: gcc-patches@gcc.gnu.org Subject: [C PATCH] Fix set_nonincremental_init_from_string (PR c/67410) Message-ID: <20160812155455.GD14857@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes 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 Martin Liska 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. Jakub --- 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; +}