aboutsummaryrefslogtreecommitdiffstats
path: root/asm/nasm.c
diff options
context:
space:
mode:
Diffstat (limited to 'asm/nasm.c')
-rw-r--r--asm/nasm.c122
1 files changed, 68 insertions, 54 deletions
diff --git a/asm/nasm.c b/asm/nasm.c
index 100e4b9c..ddc3404e 100644
--- a/asm/nasm.c
+++ b/asm/nasm.c
@@ -1768,21 +1768,35 @@ static bool skip_this_pass(int severity)
*/
static bool is_suppressed(int severity)
{
+ if ((severity & ERR_MASK) >= ERR_FATAL)
+ return false; /* Fatal errors can never be suppressed */
+
return !(warning_state[warn_index(severity)] & WARN_ST_ENABLED);
}
/**
- * check if we have a warning that should be promoted to an error
+ * Return the true error type (the ERR_MASK part) of the given
+ * severity, accounting for warnings that may need to be promoted to
+ * error.
*
* @param severity the severity of the warning or error
- * @return true if we should promote to error
+ * @return true if we should error out
*/
-static bool warning_is_error(int severity)
+static int true_error_type(int severity)
{
- if ((severity & ERR_MASK) != ERR_WARNING)
- return false; /* Other message types */
+ const uint8_t warn_is_err = WARN_ST_ENABLED|WARN_ST_ERROR;
+ int type;
+
+ type = severity & ERR_MASK;
+
+ /* Promote warning to error? */
+ if (type == ERR_WARNING) {
+ uint8_t state = warning_state[warn_index(severity)];
+ if ((state & warn_is_err) == warn_is_err)
+ type = ERR_NONFATAL;
+ }
- return !!(warning_state[warn_index(severity)] & WARN_ST_ERROR);
+ return type;
}
/**
@@ -1798,10 +1812,17 @@ static bool warning_is_error(int severity)
static void nasm_verror_asm(int severity, const char *fmt, va_list args)
{
char msg[1024];
+ char warnsuf[64];
+ char linestr[64];
const char *pfx;
- bool warn_is_err = warning_is_error(severity);
+ int spec_type = severity & ERR_MASK; /* type originally specified */
+ int true_type = true_error_type(severity);
const char *currentfile = NULL;
int32_t lineno = 0;
+ static const char * const pfx_table[ERR_MASK+1] = {
+ "debug: ", "note: ", "warning: ", "error: ",
+ "", "", "fatal: ", "panic: "
+ };
if (is_suppressed(severity))
return;
@@ -1816,53 +1837,38 @@ static void nasm_verror_asm(int severity, const char *fmt, va_list args)
lineno = 0;
}
}
- if (!currentfile)
- currentfile = "nasm";
- switch (severity & (ERR_MASK|ERR_NO_SEVERITY)) {
- case ERR_NOTE:
- pfx = "note: ";
- break;
- case ERR_WARNING:
- if (!warn_is_err) {
- pfx = "warning: ";
- break;
- }
- /* fall through */
- case ERR_NONFATAL:
- pfx = "error: ";
- break;
- case ERR_FATAL:
- pfx = "fatal: ";
- break;
- case ERR_PANIC:
- pfx = "panic: ";
- break;
- case ERR_DEBUG:
- pfx = "debug: ";
- break;
- default:
+ /*
+ * For a debug/warning/note event, if ERR_HERE is set don't
+ * output anything if there is no current filename available
+ */
+ if (!currentfile && (severity & ERR_HERE) && true_type <= ERR_WARNING)
+ return;
+
+ if (severity & ERR_NO_SEVERITY)
pfx = "";
- break;
+ else
+ pfx = pfx_table[true_type];
+
+ vsnprintf(msg, sizeof msg, fmt, args);
+ *warnsuf = 0;
+ if (spec_type == ERR_WARNING) {
+ snprintf(warnsuf, sizeof warnsuf, " [-w+%s%s]",
+ true_type ? "error=" : "",
+ warnings[warn_index(severity)].name);
}
- vsnprintf(msg, sizeof msg - 64, fmt, args);
- if ((severity & ERR_MASK) == ERR_WARNING && !is_suppressed(severity)) {
- char *p = strchr(msg, '\0');
- snprintf(p, 64, " [-w+%s%s]",
- warn_is_err ? "error=" : "",
- warnings[warn_index(severity)].name);
+ *linestr = 0;
+ if (lineno) {
+ snprintf(linestr, sizeof linestr, "%s%"PRId32"%s",
+ errfmt->beforeline, lineno, errfmt->afterline);
}
if (!skip_this_pass(severity)) {
- if (!lineno) {
- fprintf(error_file, "%s%s%s%s\n",
- currentfile, errfmt->beforemsg, pfx, msg);
- } else {
- fprintf(error_file, "%s%s%"PRId32"%s%s%s%s\n",
- currentfile, errfmt->beforeline, lineno,
- errfmt->afterline, errfmt->beforemsg, pfx, msg);
- }
+ fprintf(error_file, "%s%s%s%s%s%s%s\n",
+ currentfile ? currentfile : "nasm",
+ linestr, errfmt->beforemsg, pfx, msg,
+ (severity & ERR_HERE) ? " here" : "", warnsuf);
}
/* Are we recursing from error_list_macros? */
@@ -1873,7 +1879,19 @@ static void nasm_verror_asm(int severity, const char *fmt, va_list args)
* Don't suppress this with skip_this_pass(), or we don't get
* pass1 or preprocessor warnings in the list file
*/
- lfmt->error(severity, pfx, msg);
+ if (severity & ERR_HERE) {
+ if (lineno)
+ lfmt->error(severity, "%s%s at %s:%"PRId32"%s",
+ pfx, msg, currentfile, lineno, warnsuf);
+ else if (currentfile)
+ lfmt->error(severity, "%s%s in file %s%s",
+ pfx, msg, currentfile, warnsuf);
+ else
+ lfmt->error(severity, "%s%s in unknown location%s",
+ pfx, msg, warnsuf);
+ } else {
+ lfmt->error(severity, "%s%s%s", pfx, msg, warnsuf);
+ }
if (skip_this_pass(severity))
return;
@@ -1883,15 +1901,11 @@ static void nasm_verror_asm(int severity, const char *fmt, va_list args)
preproc->error_list_macros(severity);
- switch (severity & ERR_MASK) {
+ switch (true_type) {
case ERR_NOTE:
case ERR_DEBUG:
- /* no further action, by definition */
- break;
case ERR_WARNING:
- /* Treat warnings as errors */
- if (warning_is_error(severity))
- terminate_after_phase = true;
+ /* no further action, by definition */
break;
case ERR_NONFATAL:
terminate_after_phase = true;