Hi,

This patch sets the file location of modules created by Module::create.
It is now required to set this, as the front-end no longer uses a
fallback location if left unset.

Regstrapped on x86_64-linux-gnu, committed to mainline, and backported
to releases/gcc-15.

Regards,
Iain.

---
        PR d/122817

gcc/d/ChangeLog:

        * d-lang.cc (d_parse_file): Set module filename location after
        creation.

gcc/testsuite/ChangeLog:

        * gdc.dg/pr122817.d: New test.
---
 gcc/d/d-lang.cc                 | 2 ++
 gcc/testsuite/gdc.dg/pr122817.d | 4 ++++
 2 files changed, 6 insertions(+)
 create mode 100644 gcc/testsuite/gdc.dg/pr122817.d

diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc
index 7a016050667..4dc8eede74a 100644
--- a/gcc/d/d-lang.cc
+++ b/gcc/d/d-lang.cc
@@ -1128,6 +1128,7 @@ d_parse_file (void)
                                      Identifier::idPool ("__stdin"),
                                      global.params.ddoc.doOutput,
                                      global.params.dihdr.doOutput);
+         m->loc = Loc::singleFilename (in_fnames[i]);
          modules.push (m);
 
          /* Zero the padding past the end of the buffer so the D lexer has a
@@ -1148,6 +1149,7 @@ d_parse_file (void)
          Module *m = Module::create (in_fnames[i], Identifier::idPool (name),
                                      global.params.ddoc.doOutput,
                                      global.params.dihdr.doOutput);
+         m->loc = Loc::singleFilename (in_fnames[i]);
          modules.push (m);
          FileName::free (name);
        }
diff --git a/gcc/testsuite/gdc.dg/pr122817.d b/gcc/testsuite/gdc.dg/pr122817.d
new file mode 100644
index 00000000000..a06a011f5ad
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr122817.d
@@ -0,0 +1,4 @@
+// { dg-do compile }
+module pr122817;
+
+struct object {} // { dg-error "conflicts with import 'pr122817.object' at 
.*pr122817.d" }
-- 
2.43.0

Reply via email to