> The existing code actually appears to process .S files not .s files, and
> the existing .S tests do appear to be run, so it doesn't seem appropriate
> to stop running them.

Ouch, an annoying oversight, thanks for catching it, revised version attached.


2025-10-10  Pierre Marie de Rodat  <[email protected]>

libcpp/
        * init.c (read_original_directory): Attempt to decode escape
        sequences with cpp_interpret_string_notranslate.


2025-10-10  Eric Botcazou <[email protected]>

gcc/testsuite/
        * gcc.dg/cpp/cpp.exp: Process .i files.
        * gcc.dg/cpp/pr36674.i: Pass -Wno-implicit-int.
        * gcc.dg/cpp/escape-3.i: New test.

-- 
Eric Botcazou
diff --git a/gcc/testsuite/gcc.dg/cpp/cpp.exp b/gcc/testsuite/gcc.dg/cpp/cpp.exp
index 7a359c050e4..754ffebf9f9 100644
--- a/gcc/testsuite/gcc.dg/cpp/cpp.exp
+++ b/gcc/testsuite/gcc.dg/cpp/cpp.exp
@@ -4,12 +4,12 @@
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3 of the License, or
 # (at your option) any later version.
-# 
+#
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # along with GCC; see the file COPYING3.  If not see
 # <http://www.gnu.org/licenses/>.
@@ -36,11 +36,11 @@ if ![info exists DEFAULT_CFLAGS] then {
 dg-init
 
 # Main loop.
-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.{c,S} ]] \
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.{c,S,i} ]] \
 	"" $DEFAULT_CFLAGS
 
 # C/C++ common tests.
-dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cpp/*.{c,S} ]] \
+dg-runtest [lsort [glob -nocomplain $srcdir/c-c++-common/cpp/*.{c,S,i} ]] \
 	" -Wc++-compat " ""
 
 
diff --git a/gcc/testsuite/gcc.dg/cpp/pr36674.i b/gcc/testsuite/gcc.dg/cpp/pr36674.i
index 9362d5a4080..f4362877239 100644
--- a/gcc/testsuite/gcc.dg/cpp/pr36674.i
+++ b/gcc/testsuite/gcc.dg/cpp/pr36674.i
@@ -1,6 +1,6 @@
 /* PR cpp/36674  #include location is offset by one row in errors from preprocessed files */
 /* { dg-do compile } */
-/* { dg-options "-fshow-column" } */
+/* { dg-options "-fshow-column -Wno-implicit-int" } */
 # 1 "gcc/testsuite/gcc.dg/pr36674.c"
 # 1 "<built-in>"
 # 1 "<command-line>"
diff --git a/libcpp/init.cc b/libcpp/init.cc
index eb495e26eff..567d5e70381 100644
--- a/libcpp/init.cc
+++ b/libcpp/init.cc
@@ -893,11 +893,34 @@ read_original_directory (cpp_reader *pfile)
 
       if (pfile->cb.dir_change)
 	{
-	  /* Smash the string directly, it's dead at this point  */
-	  char *smashy = (char *)text;
-	  smashy[len - 3] = 0;
+	  cpp_string s = { 0, 0 };
+	  const char *dir_slashslash;
+	  unsigned int dir_slashslash_len;
+
+	  /* If we fail to decode escape sequences in the string literal, fall
+	     back onto the literal itself, manually removing the opening and
+	     closing quotes (").  */
+	  if (cpp_interpret_string_notranslate (pfile, &string->val.str, 1, &s,
+						CPP_STRING))
+	    {
+	      /* At this point, the trailing NUL byte in S is included in its
+		 length, so take it out.  */
+	      dir_slashslash = (const char *) s.text;
+	      dir_slashslash_len = s.len - 1;
+	    }
+	  else
+	    {
+	      dir_slashslash = (const char *) string->val.str.text + 1;
+	      dir_slashslash_len = string->val.str.len - 2;
+	    }
+
+	  /* Strip the trailing double slash.  */
+	  const unsigned dir_len = dir_slashslash_len - 2;
+	  char *dir = (char *) alloca (dir_len + 1);
+	  memcpy (dir, dir_slashslash, dir_len);
+	  dir[dir_len] = '\0';
 
-	  pfile->cb.dir_change (pfile, smashy + 1);
+	  pfile->cb.dir_change (pfile, dir);
 	}
 
       /* We should be at EOL.  */

Reply via email to