From patchwork Thu Jul 29 15:22:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1511324 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=FX6k7j/o; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GbDnT70KXz9sRf for ; Fri, 30 Jul 2021 01:23:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3FB0C39B5D1E for ; Thu, 29 Jul 2021 15:23:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3FB0C39B5D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1627572201; bh=/tP6fUZAdHY1PraZoFa+ofUMd5NagPpPl7oMO9sNN1g=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=FX6k7j/oagvaPeouempGC6dp4ESMwrv0B+qQOa2RoeVtlpvOzyafi14UVrKOqA9tj FvJauCsYdaRNPiOmbOsILswE3iSxfHahO03qi4LkkhwYzh2KDcyUWwj0H8PVBzVsfU uuK9pGPoIJdJM/sJR3FkKVcA1nEYVQiXcOdDeeYg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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) 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 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-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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: