From ccf729f6f4ae95bb5672b3ca666fe55d94f13f3a Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 8 Jun 2006 04:10:04 +0000 Subject: [PATCH] Fix cross-reference filename/line number. We were reporting (wrongly) the virtual line number rather than the physical filename/line number. This was broken when the errwarn code was changed and not caught because I didn't check the errwarn results closely enough for this case. * nasm-token.re, gas-token.re: Propagate warnings from arch early. This is a case where we probably want the double-error/warning on a single line. * errwarn.h: Add xref filename to yasm_print_error_func, and document all parameters. * errwarn.c: Get the physical file/line for xref virtual line. * yasm.c: Update to match new yasm_print_error_func definition. * pushf-err.errwarn: Correct test. svn path=/trunk/yasm/; revision=1556 --- frontends/yasm/yasm.c | 16 +++++++++------- libyasm/errwarn.c | 15 +++++++++++---- libyasm/errwarn.h | 12 ++++++++---- modules/arch/x86/tests/pushf-err.errwarn | 8 ++++---- modules/parsers/gas/gas-token.re | 2 ++ modules/parsers/nasm/nasm-token.re | 2 ++ 6 files changed, 36 insertions(+), 19 deletions(-) diff --git a/frontends/yasm/yasm.c b/frontends/yasm/yasm.c index f66e9c26..8a638a32 100644 --- a/frontends/yasm/yasm.c +++ b/frontends/yasm/yasm.c @@ -110,8 +110,9 @@ static /*@exits@*/ void handle_yasm_int_error(const char *file, static /*@exits@*/ void handle_yasm_fatal(const char *message, va_list va); static const char *handle_yasm_gettext(const char *msgid); static void print_yasm_error(const char *filename, unsigned long line, - const char *msg, unsigned long xrefline, - /*@null@*/ const char *xrefmsg); + const char *msg, /*@null@*/ const char *xref_fn, + unsigned long xref_line, + /*@null@*/ const char *xref_msg); static void print_yasm_warning(const char *filename, unsigned long line, const char *msg); @@ -1188,18 +1189,19 @@ static const char *fmt_noline[2] = { static void print_yasm_error(const char *filename, unsigned long line, const char *msg, - unsigned long xrefline, const char *xrefmsg) + const char *xref_fn, unsigned long xref_line, + const char *xref_msg) { if (line) fprintf(stderr, fmt[ewmsg_style], filename, line, "", msg); else fprintf(stderr, fmt_noline[ewmsg_style], filename, "", msg); - if (xrefmsg) { - if (xrefline) - fprintf(stderr, fmt[ewmsg_style], filename, xrefline, "", xrefmsg); + if (xref_fn && xref_msg) { + if (xref_line) + fprintf(stderr, fmt[ewmsg_style], xref_fn, xref_line, "", xref_msg); else - fprintf(stderr, fmt_noline[ewmsg_style], filename, "", xrefmsg); + fprintf(stderr, fmt_noline[ewmsg_style], xref_fn, "", xref_msg); } } diff --git a/libyasm/errwarn.c b/libyasm/errwarn.c index 44c73e89..b1f94a01 100644 --- a/libyasm/errwarn.c +++ b/libyasm/errwarn.c @@ -475,14 +475,14 @@ yasm_errwarns_output_all(yasm_errwarns *errwarns, yasm_linemap *lm, yasm_print_warning_func print_warning) { errwarn_data *we; - const char *filename; - unsigned long line; + const char *filename, *xref_filename; + unsigned long line, xref_line; /* If we're treating warnings as errors, tell the user about it. */ if (warning_as_error && warning_as_error != 2) { print_error("", 0, yasm_gettext_hook(N_("warnings being treated as errors")), - 0, NULL); + NULL, 0, NULL); warning_as_error = 2; } @@ -490,8 +490,15 @@ yasm_errwarns_output_all(yasm_errwarns *errwarns, yasm_linemap *lm, SLIST_FOREACH(we, &errwarns->errwarns, link) { /* Output error/warning */ yasm_linemap_lookup(lm, we->line, &filename, &line); + if (we->xrefline) + yasm_linemap_lookup(lm, we->xrefline, &xref_filename, &xref_line); + else { + xref_filename = NULL; + xref_line = 0; + } if (we->type == WE_ERROR || we->type == WE_PARSERERROR) - print_error(filename, line, we->msg, we->xrefline, we->xrefmsg); + print_error(filename, line, we->msg, xref_filename, xref_line, + we->xrefmsg); else print_warning(filename, line, we->msg); } diff --git a/libyasm/errwarn.h b/libyasm/errwarn.h index 1a9e82f2..f76d6d24 100644 --- a/libyasm/errwarn.h +++ b/libyasm/errwarn.h @@ -264,13 +264,17 @@ unsigned int yasm_errwarns_num_errors(yasm_errwarns *errwarns, int warning_as_error); /** Print out an error. - * \param fn filename of source file - * \param line line number - * \param msg error message + * \param fn filename of source file + * \param line line number + * \param msg error message + * \param xref_fn cross-referenced source filename + * \param xref_line cross-referenced line number + * \param xref_msg cross-referenced error message */ typedef void (*yasm_print_error_func) (const char *fn, unsigned long line, const char *msg, - unsigned long xrefline, /*@null@*/ const char *xrefmsg); + /*@null@*/ const char *xref_fn, unsigned long xref_line, + /*@null@*/ const char *xref_msg); /** Print out a warning. * \param fn filename of source file diff --git a/modules/arch/x86/tests/pushf-err.errwarn b/modules/arch/x86/tests/pushf-err.errwarn index 21e094f3..79f3177a 100644 --- a/modules/arch/x86/tests/pushf-err.errwarn +++ b/modules/arch/x86/tests/pushf-err.errwarn @@ -1,10 +1,10 @@ -:5: warning: `pushfq' is an instruction in 64-bit mode -:9: warning: `popfq' is an instruction in 64-bit mode --:15: redefinition of `pushfq' --:10: `pushfq' previously defined here -:15: warning: `pushfq' is an instruction in 64-bit mode --:19: redefinition of `popfq' --:18: `popfq' previously defined here +-:15: redefinition of `pushfq' +-:5: `pushfq' previously defined here -:19: warning: `popfq' is an instruction in 64-bit mode +-:19: redefinition of `popfq' +-:9: `popfq' previously defined here -:24: `pushfd' invalid in 64-bit mode -:28: `popfd' invalid in 64-bit mode diff --git a/modules/parsers/gas/gas-token.re b/modules/parsers/gas/gas-token.re index 5977b158..6edbc4c3 100644 --- a/modules/parsers/gas/gas-token.re +++ b/modules/parsers/gas/gas-token.re @@ -471,6 +471,8 @@ scan: s->tok[TOKLEN] = savech; } } + /* Propagate errors in case we got a warning from the arch */ + yasm_errwarn_propagate(parser_gas->errwarns, cur_line); /* Just an identifier, return as such. */ lvalp->str_val = yasm__xstrndup(TOK, TOKLEN); RETURN(ID); diff --git a/modules/parsers/nasm/nasm-token.re b/modules/parsers/nasm/nasm-token.re index 4030e0d9..b8f9b135 100644 --- a/modules/parsers/nasm/nasm-token.re +++ b/modules/parsers/nasm/nasm-token.re @@ -410,6 +410,8 @@ scan: default: s->tok[TOKLEN] = savech; } + /* Propagate errors in case we got a warning from the arch */ + yasm_errwarn_propagate(parser_nasm->errwarns, cur_line); /* Just an identifier, return as such. */ lvalp->str_val = yasm__xstrndup(TOK, TOKLEN); RETURN(ID); -- 2.40.0