From patchwork Thu Sep 1 12:33:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 896 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp229443wro; Thu, 1 Sep 2022 05:34:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR6lNvcPp6ecgmvV2uvzG5ABYvbooCvLCOuwM7mgPGOBCSSbbA6j8QtV0fSTX5ckb6g8UlT6 X-Received: by 2002:aa7:d292:0:b0:447:f99d:8b9b with SMTP id w18-20020aa7d292000000b00447f99d8b9bmr23617099edq.29.1662035663787; Thu, 01 Sep 2022 05:34:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662035663; cv=none; d=google.com; s=arc-20160816; b=PK556Y4h0pOael+DOyXrWlWer/3vQWZcX9iUq0O8lzzOG6riG0HhM39QdeUETEr8dy bhxI89nUu9J/hZeSJmWDUb7a+Ys40JtOPVblV98Z/qdA1FX5q5NqZD1oXRgltzPlxFMi ekdvUPabHpHjMnRwCLnSNrkH7orObAPC4wF0NP3SdqjSjRHf0Oqw+JXSgPYBzv88MM1A L9Kp1v2cUK4fYxSl2wmJIfTJ+0a+aNcTtVFmKEk2Y3QR9ks1Fc7AcLZUzlqu8KudqCvr sEDykVWvQPTREuxgCMFE/K0lXtDj9tdvgSZC3+82sG5C1BDSjaZjTsidYxy5KKBkbVC8 4keQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=CajughsbPqeyOv1zcfaloZNdHPoEc1PWbjoJfBWTmek=; b=ShmraU7VMYRGJXWCZiPkHUKhlMF1qOC9iekxq1DjZMt3WTRilwoAguIIhK9Omrn87N jKOe4HALo9FtPYbN+zN3kbrNQDL0RFrzZ98cOkDagWX6iuEerT+0VSyu6MxF9OQ5ybau j/2ZJMcLN4GCWp8WZUXAQJB1aTvgplRdGp8AMOUxH72dKsYdxj0ghc8Ie2U1RYQ4w0UM N7qPaaj5bn6SE2QA1VmMV0PFKBXUVSaJ5drFdtS75Z5Wq2/h95VMiiKbvKO6PiER+ADA RoXCzpMD46YbcRzMFvp86W1CaHOIPCK1Ff2QKixtsJo4lGrE55TBiUZu0qHMu2ik775y 50jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rAdY0TvS; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id jr19-20020a170906a99300b0072aeac5f74bsi11663303ejb.119.2022.09.01.05.34.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 05:34:23 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rAdY0TvS; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 590583858C39 for ; Thu, 1 Sep 2022 12:34:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 590583858C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662035662; bh=CajughsbPqeyOv1zcfaloZNdHPoEc1PWbjoJfBWTmek=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=rAdY0TvSYut0043+vnNLpR4hX4MdAzebicQ6J5zEIM5+ZGKmdNPClET08EYxDO2kZ 4y0DCyiaKh9kltyMtghZMgpWKX583mZ1Cg4cUKPExhiH8rtRXMo6rkGfR+llRk3pzn 69aCZhP8SRRTMiG/i5WI54zU1XkYGPZk5pkEdsBU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 20A633858D37 for ; Thu, 1 Sep 2022 12:33:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 20A633858D37 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-388-T1KA1K6-MQGpMcwaA5XapQ-1; Thu, 01 Sep 2022 08:33:38 -0400 X-MC-Unique: T1KA1K6-MQGpMcwaA5XapQ-1 Received: by mail-qk1-f197.google.com with SMTP id bp11-20020a05620a458b00b006bbeffab91dso14071461qkb.11 for ; Thu, 01 Sep 2022 05:33:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc; bh=CajughsbPqeyOv1zcfaloZNdHPoEc1PWbjoJfBWTmek=; b=FaEYpt1bRAlD/pQGRSRqTfmNNpg30kq2AEIiM7DliXCrFKwSB6FYhNzXLZ8PJBAhgs BV/OLtbV8oUaImFUAvjR4vz7NfxU5p7Ye32qw6Lab1xw4JjzTDjgLwy5/lnUihzUxTzt 1lb1yl2VfFfkyA05pjFml+d8GYeucD4GwK32/+Mp7zP3X5GiTbahbcBRTOph5Kgxq1PN xPSFJdJ92LdJ7hDtVK0Tum1dngKBxQi8rufPdxym70INxobFePHWvBl/WnfvaiAciMCN UJKTFwcUmKZDaMALMF3im/XHyVQcQhg1l/MpqRnHBxxSzjhJBbRPvDdvuCP+9iU75GsF IFHA== X-Gm-Message-State: ACgBeo0Y+mtix+gmTkRphp56CM/xA6+VRmi7ksqDJdUfUak8n0nupKYD Oz2RcYgUfsOTTtVflF0yZm/XXUVWjdNO1P6jWcDSmo0BQCdgZpt97oIFg+6fqW23rScDKpq20us L7l19T5HafLf2u94eZz81u8szSWBG8zK79BcUN+QIa61LRDzeUDO6TvjXjI8mImboEg== X-Received: by 2002:a37:2758:0:b0:6bb:2e8:8637 with SMTP id n85-20020a372758000000b006bb02e88637mr19046860qkn.126.1662035618050; Thu, 01 Sep 2022 05:33:38 -0700 (PDT) X-Received: by 2002:a37:2758:0:b0:6bb:2e8:8637 with SMTP id n85-20020a372758000000b006bb02e88637mr19046834qkn.126.1662035617669; Thu, 01 Sep 2022 05:33:37 -0700 (PDT) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id x22-20020a05620a449600b006af10bd3635sm12887328qkp.57.2022.09.01.05.33.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 05:33:37 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: set TYPE_STRING_FLAG for char8_t Date: Thu, 1 Sep 2022 08:33:35 -0400 Message-Id: <20220901123335.4066778-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742770708216643735?= X-GMAIL-MSGID: =?utf-8?q?1742770708216643735?= 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. Tested x86_64-pc-linux-gnu, applying to trunk. 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. --- gcc/c-family/c-common.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) base-commit: 25dd2768afdb8fad7b11d511eb5f739958f9870d diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc index 71fe7305369..9b07a1cbae3 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); @@ -9343,12 +9344,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