]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
d: Don't escape quoted format strings in escape_d_format (PR101656)
authorIain Buclaw <ibuclaw@gdcproject.org>
Mon, 26 Jul 2021 13:52:23 +0000 (15:52 +0200)
committerIain Buclaw <ibuclaw@gdcproject.org>
Thu, 29 Jul 2021 14:16:19 +0000 (16:16 +0200)
If the format string is enclosed by two '`' characters, then don't
escape the first and laster characters.

PR d/101656

gcc/d/ChangeLog:

* d-diagnostic.cc (escape_d_format): Don't escape quoted format
strings.

gcc/d/d-diagnostic.cc

index 7043abe10bd860289cce30a28b0fe01f1cc4a60d..1982bd954a8f086514e1774fa867fa85c6b3c029 100644 (file)
@@ -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: