]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Handle absolute path for CMI output directory [PR122677]
authorJonathan Wakely <jwakely@redhat.com>
Tue, 18 Nov 2025 13:19:53 +0000 (13:19 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 18 Nov 2025 17:10:47 +0000 (17:10 +0000)
When trying to create each directory component of an absolute path, the
first call to mkdir uses a path of "" which gives an ENOENT error. This
causes the create_dirs function to return without creating anything.

This commit skips past the leading slashes of an absolute path, so that
the first call to mkdir is for an actual directory name, not an empty
string.

gcc/cp/ChangeLog:

PR c++/122677
* module.cc (create_dirs): Skip past any leading slashes.

gcc/cp/module.cc

index 017bacdf22314863e144b59be3c96d52e69e5864..40f592b7a2ff8066707e622dd48d4387388af06d 100644 (file)
@@ -4941,8 +4941,13 @@ maybe_add_cmi_prefix (const char *to, size_t *len_p = NULL)
 static void
 create_dirs (char *path)
 {
+  char *base = path;
+  /* Skip past initial slashes of absolute path.  */
+  while (IS_DIR_SEPARATOR (*base))
+    base++;
+
   /* Try and create the missing directories.  */
-  for (char *base = path; *base; base++)
+  for (; *base; base++)
     if (IS_DIR_SEPARATOR (*base))
       {
        char sep = *base;