On Tue, 18 Nov 2025 at 17:04, Jason Merrill <[email protected]> wrote:
>
> On 11/18/25 7:07 PM, Jonathan Wakely wrote:
> > 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.
> > ---
> >
> > As discussed in the PR, this is difficult to test because we don't
> > really want the testsuite creating directories in hardcoded absolute
> > paths like /tmp/gcm.cache and it's not trivial to pass the absolute path
> > of the build directory to the test (and then have that directory removed
> > again afterwards). But this has been manually tested with absolute paths
> > and it fixes the bug. The rest of the testsuite was run on x86_64-linux.
> >
> > OK for trunk? Is it needed for gcc-15 too?
>
> OK. I think it's worth applying to 15 as well.
Will do, thanks. The bug was reported against gcc-15 so I agree it's
worth backporting.
>
> > gcc/cp/module.cc | 7 ++++++-
> > 1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
> > index 017bacdf2231..40f592b7a2ff 100644
> > --- a/gcc/cp/module.cc
> > +++ b/gcc/cp/module.cc
> > @@ -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;
>