diff options
| author | Eugen Wissner <belka@caraus.de> | 2026-07-06 10:44:15 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2026-07-07 00:47:59 +0200 |
| commit | 470bfba45661d19558c0bf43b7819696a925ecb4 (patch) | |
| tree | 44eef131a3edca1cc5489fa45851a5d5685ec530 /gcc | |
| parent | 8ea930783d15c04bbe9a027eaf19ca10e2cd87c0 (diff) | |
| download | elna-470bfba45661d19558c0bf43b7819696a925ecb4.tar.gz | |
Fix compiler crashing on syntax errors
after error reporting.
Diffstat (limited to 'gcc')
| -rw-r--r-- | gcc/gcc/elna-diagnostic.cc | 7 | ||||
| -rw-r--r-- | gcc/gcc/elna-generic.cc | 2 | ||||
| -rw-r--r-- | gcc/gcc/elna-tree.cc | 2 | ||||
| -rw-r--r-- | gcc/gcc/elna1.cc | 66 |
4 files changed, 44 insertions, 33 deletions
diff --git a/gcc/gcc/elna-diagnostic.cc b/gcc/gcc/elna-diagnostic.cc index fa32788..509871c 100644 --- a/gcc/gcc/elna-diagnostic.cc +++ b/gcc/gcc/elna-diagnostic.cc @@ -26,6 +26,13 @@ namespace elna::gcc linemap_add(line_table, LC_ENTER, 0, filename, 1); } + linemap_guard::linemap_guard(const std::filesystem::path filename) + { + const char *filename_pointer = ggc_strdup(filename.native().c_str()); + + linemap_add(line_table, LC_ENTER, 0, filename_pointer, 1); + } + linemap_guard::~linemap_guard() { linemap_add(line_table, LC_LEAVE, 0, NULL, 0); diff --git a/gcc/gcc/elna-generic.cc b/gcc/gcc/elna-generic.cc index 2c16a37..eb30b4d 100644 --- a/gcc/gcc/elna-generic.cc +++ b/gcc/gcc/elna-generic.cc @@ -17,8 +17,8 @@ along with GCC; see the file COPYING3. If not see #include <array> -#include "elna/gcc/elna-generic.h" #include "elna/gcc/elna-diagnostic.h" +#include "elna/gcc/elna-generic.h" #include "elna/gcc/elna1.h" #include "elna/gcc/elna-builtins.h" diff --git a/gcc/gcc/elna-tree.cc b/gcc/gcc/elna-tree.cc index de7f6b0..835702a 100644 --- a/gcc/gcc/elna-tree.cc +++ b/gcc/gcc/elna-tree.cc @@ -15,8 +15,8 @@ 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/>. */ -#include "elna/gcc/elna-tree.h" #include "elna/gcc/elna-diagnostic.h" +#include "elna/gcc/elna-tree.h" #include "elna/gcc/elna1.h" #include "function.h" diff --git a/gcc/gcc/elna1.cc b/gcc/gcc/elna1.cc index 0333f70..c87d462 100644 --- a/gcc/gcc/elna1.cc +++ b/gcc/gcc/elna1.cc @@ -15,6 +15,14 @@ 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/>. */ +#include <fstream> + +#include "elna/gcc/elna-diagnostic.h" +#include "elna/boot/dependency.h" +#include "elna/gcc/elna-tree.h" +#include "elna/gcc/elna-generic.h" +#include "elna/gcc/elna-builtins.h" + #include "config.h" #include "system.h" #include "coretypes.h" @@ -28,13 +36,6 @@ along with GCC; see the file COPYING3. If not see #include "langhooks.h" #include "langhooks-def.h" -#include <fstream> -#include "elna/boot/dependency.h" -#include "elna/gcc/elna-tree.h" -#include "elna/gcc/elna-generic.h" -#include "elna/gcc/elna-diagnostic.h" -#include "elna/gcc/elna-builtins.h" - tree elna_global_trees[ELNA_TI_MAX]; hash_map<nofree_string_hash, tree> *elna_global_decls = nullptr; @@ -73,36 +74,36 @@ static elna::boot::dependency elna_parse_file(dependency_state& state, const cha fatal_error(UNKNOWN_LOCATION, "Cannot open filename %s: %m", filename); } elna::gcc::linemap_guard{ filename }; - elna::boot::dependency outcome = elna::boot::read_source(entry_point, filename); + elna::boot::dependency outcome = elna::boot::read_source(entry_point); - if (outcome.has_errors()) - { - elna::gcc::report_errors(outcome.errors()); - return outcome; - } - elna::boot::symbol_bag outcome_bag = elna::boot::symbol_bag{ std::move(outcome.unresolved), state.globals }; + elna::boot::symbol_bag outcome_bag{ std::move(outcome.unresolved), state.globals }; - for (const auto& sub_tree : outcome.tree->imports) + if (!outcome.has_errors()) { - std::filesystem::path sub_path = "source" / elna::boot::build_path(sub_tree->segments); - std::unordered_map<std::filesystem::path, elna::boot::symbol_bag>::const_iterator cached_import = - state.cache.find(sub_path); - - if (cached_import == state.cache.end()) + for (elna::boot::import_declaration const* sub_tree : outcome.tree->imports) { - elna_parse_file(state, sub_path.c_str()); - cached_import = state.cache.find(sub_path); + std::filesystem::path sub_path = "source" / elna::boot::build_path(sub_tree->segments); + dependency_state::const_iterator cached_import = state.find(sub_path); + + if (cached_import == state.cend()) + { + auto filename_pointer = ggc_strdup(sub_path.native().c_str()); + + elna_parse_file(state, filename_pointer); + cached_import = state.find(sub_path); + } + if (cached_import != state.cend()) + { + outcome_bag.add_import(cached_import->second); + } } - outcome_bag.add_import(cached_import->second); + outcome.errors() = analyze_semantics(outcome.tree, outcome_bag); } - outcome.errors() = analyze_semantics(filename, outcome.tree, outcome_bag); - if (outcome.has_errors()) { elna::gcc::report_errors(outcome.errors()); - return outcome; } - state.cache.insert({ filename, outcome_bag }); + state.insert(filename, outcome_bag); elna::gcc::rewrite_symbol_table(outcome_bag.leave(), state.custom); return outcome; @@ -116,10 +117,13 @@ static void elna_langhook_parse_file(void) { elna::boot::dependency outcome = elna_parse_file(state, in_fnames[i]); - linemap_add(line_table, LC_ENTER, 0, in_fnames[i], 1); - elna::gcc::generic_visitor generic_visitor{ state.custom, state.cache.find(in_fnames[i])->second }; - outcome.tree->accept(&generic_visitor); - linemap_add(line_table, LC_LEAVE, 0, NULL, 0); + if (!outcome.has_errors()) + { + linemap_add(line_table, LC_ENTER, 0, in_fnames[i], 1); + elna::gcc::generic_visitor generic_visitor{ state.custom, state.find(in_fnames[i])->second }; + outcome.tree->accept(&generic_visitor); + linemap_add(line_table, LC_LEAVE, 0, NULL, 0); + } } } |
