From 8e655a0786aec5e0215e09f2a9629c6f32e34793 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 28 Aug 2026 02:39:42 +0200 Subject: Reject declarations shadowing imports --- gcc/gcc/elna-diagnostic.cc | 25 +++++++++++++++++++++---- gcc/gcc/elna-module-loader.cc | 15 ++++++++++++--- 2 files changed, 33 insertions(+), 7 deletions(-) (limited to 'gcc') diff --git a/gcc/gcc/elna-diagnostic.cc b/gcc/gcc/elna-diagnostic.cc index ea1f64c..1a65eed 100644 --- a/gcc/gcc/elna-diagnostic.cc +++ b/gcc/gcc/elna-diagnostic.cc @@ -63,9 +63,11 @@ namespace elna::gcc return make_location(caret, start, end); } - void report_errors(const std::deque>& errors) + void report_errors(const boot::module_diagnostics& diagnostics) { - for (const auto& error : errors) + const linemap_guard guard(diagnostics.module); + + for (const auto& error : diagnostics.errors()) { if (error->position.start().available()) { @@ -79,8 +81,23 @@ namespace elna::gcc } if (auto note = error->note()) { - const location_t note_loc = make_range(note->second); - inform(note_loc, "%s", note->first.c_str()); + if (note->file.empty()) + { + const location_t note_loc = make_range(note->position); + inform(note_loc, "%s", note->message.c_str()); + } + else + { + // Positions carry no file identity; render the note under + // a map of the module the note points into. LC_RENAME + // continues the current map under the new name without + // recording an include edge, so no "In file included + // from" chain is printed for the note. + linemap_add(line_table, LC_RENAME, 0, ggc_strdup(note->file.native().c_str()), 1); + const location_t note_loc = make_range(note->position); + inform(note_loc, "%s", note->message.c_str()); + linemap_add(line_table, LC_RENAME, 0, ggc_strdup(diagnostics.module.native().c_str()), 1); + } } } } diff --git a/gcc/gcc/elna-module-loader.cc b/gcc/gcc/elna-module-loader.cc index 1dd7596..8827a1e 100644 --- a/gcc/gcc/elna-module-loader.cc +++ b/gcc/gcc/elna-module-loader.cc @@ -33,7 +33,7 @@ namespace elna::gcc } std::filesystem::path module_loader::resolve(const std::filesystem::path& relative, - const boot::source_position& position) + const boot::source_position& position, const std::filesystem::path& module) { std::vector found; @@ -52,14 +52,20 @@ namespace elna::gcc } if (found.size() > 1) { + const linemap_guard guard(module); const location_t gcc_location = get_location(&position); error_at(gcc_location, "Module %s was found in more than one include path", relative.native().c_str()); + + for (const auto& candidate : found) + { + inform(UNKNOWN_LOCATION, " %s", candidate.native().c_str()); + } } return std::filesystem::weakly_canonical(found.front()); } - boot::dependency module_loader::read(const std::filesystem::path& key) + boot::read_result module_loader::read(const std::filesystem::path& key) { std::ifstream entry_point{ key, std::ios::in }; @@ -88,7 +94,10 @@ namespace elna::gcc const std::filesystem::path key = std::filesystem::weakly_canonical(filenames[i]); boot::dependency result = state.compile(key, loader, target); - report_errors(result.errors); + for (const auto& diagnostics : result.errors) + { + report_errors(diagnostics); + } if (result.value != nullptr) { -- cgit v1.2.3