From 2799799358295075579dbd737a6e3f5c200d2a6d Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sat, 24 Feb 2024 13:30:27 +0000 Subject: [PATCH] Make compiler return non-zero exit code when include file not found. Most pre-processor errors are flagged to the main compiler by a comment at the end of the pre-processed output. But certain errors, such as failing to find or open an include file, cause the pre-processor to exit immediately, which bypassed the generation of that comment. So we need to also generate that comment for all early-exit cases. This fixes issue #1104. --- ivlpp/lexor.lex | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ivlpp/lexor.lex b/ivlpp/lexor.lex index c47dbed40..960d74045 100644 --- a/ivlpp/lexor.lex +++ b/ivlpp/lexor.lex @@ -1015,13 +1015,19 @@ static /* inline */ char* def_argv(int arg) return def_buf + def_argo[arg]; } +static void early_exit(void) +{ + fprintf(yyout, "// Icarus preprocessor had (%u) errors.\n", error_count); + exit(1); +} + static void check_for_max_args(void) { if (def_argc == MAX_DEF_ARG) { emit_pathline(istack); fprintf(stderr, "error: too many macro arguments - aborting\n"); error_count += 1; - exit(1); + early_exit(); } } @@ -1930,7 +1936,7 @@ static void include_filename(int macro_str) fprintf(stderr, "error: malformed `include directive. Extra junk on line?\n"); error_count += 1; - exit(1); + early_exit(); } standby = malloc(sizeof(struct include_stack_t)); @@ -1987,7 +1993,8 @@ static void do_include(void) emit_pathline(istack); fprintf(stderr, "Include file %s not found\n", standby->path); - exit(1); + error_count += 1; + early_exit(); code_that_switches_buffers: @@ -2366,7 +2373,8 @@ void reset_lexor(FILE* out, char* paths[]) if (isp->file == 0) { perror(paths[0]); - exit(1); + error_count += 1; + early_exit(); } if (depend_file) {