* [committed] d: Don't escape quoted format strings in escape_d_format (PR101656)
@ 2021-07-29 15:22 Iain Buclaw
0 siblings, 0 replies; only message in thread
From: Iain Buclaw @ 2021-07-29 15:22 UTC (permalink / raw)
To: 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:
--
2.30.2
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-07-29 15:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-29 15:22 [committed] d: Don't escape quoted format strings in escape_d_format (PR101656) Iain Buclaw
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).