From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by sourceware.org (Postfix) with ESMTPS id 68DD7384F014 for ; Thu, 29 Jul 2021 15:22:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 68DD7384F014 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4GbDmX153RzQjgR; Thu, 29 Jul 2021 17:22:36 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter04.heinlein-hosting.de (spamfilter04.heinlein-hosting.de [80.241.56.122]) (amavisd-new, port 10030) with ESMTP id fbfJZ-vaOI3n; Thu, 29 Jul 2021 17:22:29 +0200 (CEST) From: Iain Buclaw To: gcc-patches@gcc.gnu.org Subject: [committed] d: Don't escape quoted format strings in escape_d_format (PR101656) Date: Thu, 29 Jul 2021 17:22:27 +0200 Message-Id: <20210729152227.273159-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 3953818BB X-Rspamd-UID: 230777 X-Spam-Status: No, score=-15.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Thu, 29 Jul 2021 15:22:39 -0000 Hi, This patch prepares the escape_d_format function to handle being given a quoted string. Something that the self-hosted D front-end does with a new format helper for symbols. If the format string is enclosed by two '`' characters, then don't escape the first and laster characters. There are no tests as only the self-hosted front-end has the necessary change that turns this on. Bootstrapped and regression tested on x86_64-linux-gnu/-mx32/-m32, and committed to mainline. Regards, Iain --- gcc/d/ChangeLog: PR d/101656 * d-diagnostic.cc (escape_d_format): Don't escape quoted format strings. --- gcc/d/d-diagnostic.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gcc/d/d-diagnostic.cc b/gcc/d/d-diagnostic.cc index 7043abe10bd..1982bd954a8 100644 --- a/gcc/d/d-diagnostic.cc +++ b/gcc/d/d-diagnostic.cc @@ -135,10 +135,21 @@ expand_d_format (const char *format) static char * escape_d_format (const char *format) { + bool quoted = false; + size_t format_len = 0; obstack buf; gcc_obstack_init (&buf); + /* If the format string is enclosed by two '`' characters, then don't escape + the first and last characters. */ + if (*format == '`') + { + format_len = strlen (format) - 1; + if (format_len && format[format_len] == '`') + quoted = true; + } + for (const char *p = format; *p; p++) { switch (*p) @@ -152,7 +163,8 @@ escape_d_format (const char *format) case '`': /* Escape '`' characters so that expand_d_format does not confuse them for a quoted string. */ - obstack_1grow (&buf, '\\'); + if (!quoted || (p != format && p != (format + format_len))) + obstack_1grow (&buf, '\\'); break; default: -- 2.30.2