From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 504FB3858299; Thu, 1 Sep 2022 12:33:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 504FB3858299 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662035631; bh=l5z8ZYiyNg01vOpqoRE4eMduILT2mCDG/w28qk9c5VU=; h=From:To:Subject:Date:From; b=FaU0axBXAg9yV3GGQPM4MBClGx97deW1iIisbfpMJ9Z7KZ6PUWFERDoW3dbbhPkX9 16TmGw7UMoMlEiNu/v7iH5y5OUaupQUMATuJCKllaJbusf/FTTJ+3YNRb4a0QhzUMm 8rEmondGOZQI//IeQFe8X73iaUhGJ0YoJ7onNyX4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-2340] c++: set TYPE_STRING_FLAG for char8_t X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/master X-Git-Oldrev: 0550e306d4b5aaf7bdb6e908d265dbaa63344271 X-Git-Newrev: c5699dd82aa053a8597a69f3331f11aff3e2823d Message-Id: <20220901123351.504FB3858299@sourceware.org> Date: Thu, 1 Sep 2022 12:33:51 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c5699dd82aa053a8597a69f3331f11aff3e2823d commit r13-2340-gc5699dd82aa053a8597a69f3331f11aff3e2823d Author: Jason Merrill Date: Wed Aug 24 16:31:11 2022 -0400 c++: set TYPE_STRING_FLAG for char8_t While looking at the DWARF handling of char8_t I wondered why we weren't setting TREE_STRING_FLAG on it. I hoped that setting that flag would be an easy fix for PR102958, but it doesn't seem to be sufficicent. But it still seems correct. I also tried setting the flag on char16_t and char32_t, but that broke because braced_list_to_string assumes char-sized elements. Since we don't set the flag on wchar_t, I abandoned that idea. gcc/c-family/ChangeLog: * c-common.cc (c_common_nodes_and_builtins): Set TREE_STRING_FLAG on char8_t. (braced_list_to_string): Check for char-sized elements. Diff: --- gcc/c-family/c-common.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc index 1eb842e1c7b..9746504195b 100644 --- a/gcc/c-family/c-common.cc +++ b/gcc/c-family/c-common.cc @@ -4550,6 +4550,7 @@ c_common_nodes_and_builtins (void) if (c_dialect_cxx ()) { char8_type_node = make_unsigned_type (char8_type_size); + TYPE_STRING_FLAG (char8_type_node) = true; if (flag_char8_t) record_builtin_type (RID_CHAR8, "char8_t", char8_type_node); @@ -9345,12 +9346,15 @@ braced_list_to_string (tree type, tree ctor, bool member) if (!member && !tree_fits_uhwi_p (typesize)) return ctor; - /* If the target char size differes from the host char size, we'd risk + /* If the target char size differs from the host char size, we'd risk loosing data and getting object sizes wrong by converting to host chars. */ if (TYPE_PRECISION (char_type_node) != CHAR_BIT) return ctor; + /* STRING_CST doesn't support wide characters. */ + gcc_checking_assert (TYPE_PRECISION (TREE_TYPE (type)) == CHAR_BIT); + /* If the array has an explicit bound, use it to constrain the size of the string. If it doesn't, be sure to create a string that's as long as implied by the index of the last zero specified via