mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-10-10 00:25:06 -04:00
Make -Werror controllable on a per-warning-class basis
Make -Werror possible to control on a per-warning-class basis. While I was fixing up that code anyway, merge the handling of the -w, -W and [warning] argument and directives. Furthermore, make *all* warnings suppressible; any warning that isn't categorized now belong to category "other". However, for cleanliness sake an "other" option does not get listed in the warning messages. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
@@ -480,37 +480,11 @@ bool process_directives(char *directive)
|
||||
}
|
||||
|
||||
case D_WARNING: /* [WARNING {+|-|*}warn-name] */
|
||||
{
|
||||
enum warn_action { WID_OFF, WID_ON, WID_RESET };
|
||||
enum warn_action action;
|
||||
int i;
|
||||
|
||||
value = nasm_skip_spaces(value);
|
||||
switch(*value) {
|
||||
case '-': action = WID_OFF; value++; break;
|
||||
case '+': action = WID_ON; value++; break;
|
||||
case '*': action = WID_RESET; value++; break;
|
||||
default: action = WID_ON; break;
|
||||
if (!set_warning_status(value)) {
|
||||
nasm_error(ERR_WARNING|ERR_WARN_UNK_WARNING,
|
||||
"unknown warning option: %s", value);
|
||||
}
|
||||
|
||||
for (i = 1; i <= ERR_WARN_MAX; i++)
|
||||
if (!nasm_stricmp(value, warnings[i].name))
|
||||
break;
|
||||
if (i <= ERR_WARN_MAX) {
|
||||
switch (action) {
|
||||
case WID_OFF:
|
||||
warning_on[i] = false;
|
||||
break;
|
||||
case WID_ON:
|
||||
warning_on[i] = true;
|
||||
break;
|
||||
case WID_RESET:
|
||||
warning_on[i] = warning_on_global[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case D_CPU: /* [CPU] */
|
||||
cpu = get_cpu(value);
|
||||
|
110
asm/error.c
110
asm/error.c
@@ -1,5 +1,5 @@
|
||||
/* ----------------------------------------------------------------------- *
|
||||
*
|
||||
*
|
||||
* Copyright 1996-2017 The NASM Authors - All Rights Reserved
|
||||
* See the file AUTHORS included with the NASM distribution for
|
||||
* the specific copyright holders.
|
||||
@@ -14,7 +14,7 @@
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
@@ -44,11 +44,10 @@
|
||||
|
||||
/*
|
||||
* Description of the suppressible warnings for the command line and
|
||||
* the [warning] directive. Entry zero isn't an actual warning, but
|
||||
* it used for -w+error/-Werror.
|
||||
* the [warning] directive.
|
||||
*/
|
||||
const struct warning warnings[ERR_WARN_MAX+1] = {
|
||||
{"error", "treat warnings as errors", false},
|
||||
const struct warning warnings[ERR_WARN_ALL+1] = {
|
||||
{"other", "any warning not specifially mentioned below", true},
|
||||
{"macro-params", "macro calls with wrong parameter count", true},
|
||||
{"macro-selfref", "cyclic macro references", false},
|
||||
{"macro-defaults", "macros with more default than optional parameters", true},
|
||||
@@ -67,10 +66,15 @@ const struct warning warnings[ERR_WARN_MAX+1] = {
|
||||
{"ptr", "non-NASM keyword used in other assemblers", true},
|
||||
{"bad-pragma", "empty or malformed %pragma", false},
|
||||
{"unknown-pragma", "unknown %pragma facility or directive", false},
|
||||
{"not-my-pragma", "%pragma not applicable to this compilation", false}
|
||||
{"not-my-pragma", "%pragma not applicable to this compilation", false},
|
||||
{"unknown-warning", "unknown warning in -W/-w or warning directive", false},
|
||||
|
||||
/* THIS ENTRY MUST COME LAST */
|
||||
{"all", "all possible warnings", false}
|
||||
};
|
||||
bool warning_on[ERR_WARN_MAX+1]; /* Current state */
|
||||
bool warning_on_global[ERR_WARN_MAX+1]; /* Command-line state, for reset */
|
||||
|
||||
uint8_t warning_state[ERR_WARN_ALL];/* Current state */
|
||||
uint8_t warning_state_init[ERR_WARN_ALL]; /* Command-line state, for reset */
|
||||
|
||||
vefunc nasm_verror; /* Global error handling function */
|
||||
|
||||
@@ -108,5 +112,91 @@ no_return nasm_panic_from_macro(const char *file, int line)
|
||||
|
||||
no_return nasm_assert_failed(const char *file, int line, const char *msg)
|
||||
{
|
||||
nasm_fatal(0, "assertion %s failed at %s:%d", msg, file, line);
|
||||
nasm_panic(0, "assertion %s failed at %s:%d", msg, file, line);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is called when processing a -w or -W option, or a warning directive.
|
||||
* Returns true if if the action was successful.
|
||||
*/
|
||||
bool set_warning_status(const char *value)
|
||||
{
|
||||
enum warn_action { WID_OFF, WID_ON, WID_RESET };
|
||||
enum warn_action action;
|
||||
uint8_t mask;
|
||||
int i;
|
||||
bool ok = false;
|
||||
|
||||
value = nasm_skip_spaces(value);
|
||||
switch (*value) {
|
||||
case '-':
|
||||
action = WID_OFF;
|
||||
value++;
|
||||
break;
|
||||
case '+':
|
||||
action = WID_ON;
|
||||
value++;
|
||||
break;
|
||||
case '*':
|
||||
action = WID_RESET;
|
||||
value++;
|
||||
break;
|
||||
case 'N':
|
||||
case 'n':
|
||||
if (!nasm_strnicmp(value, "no-", 3)) {
|
||||
action = WID_OFF;
|
||||
value += 3;
|
||||
break;
|
||||
} else if (!nasm_stricmp(value, "none")) {
|
||||
action = WID_OFF;
|
||||
value = NULL;
|
||||
break;
|
||||
}
|
||||
/* else fall through */
|
||||
default:
|
||||
action = WID_ON;
|
||||
break;
|
||||
}
|
||||
|
||||
mask = WARN_ST_ENABLED;
|
||||
|
||||
if (value && !nasm_strnicmp(value, "error", 5)) {
|
||||
switch (value[5]) {
|
||||
case '=':
|
||||
mask = WARN_ST_ERROR;
|
||||
value += 6;
|
||||
break;
|
||||
case '\0':
|
||||
mask = WARN_ST_ERROR;
|
||||
value = NULL;
|
||||
break;
|
||||
default:
|
||||
/* Just an accidental prefix? */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (value && !nasm_stricmp(value, "all"))
|
||||
value = NULL;
|
||||
|
||||
/* This is inefficient, but it shouldn't matter... */
|
||||
for (i = 0; i < ERR_WARN_ALL; i++) {
|
||||
if (!value || !nasm_stricmp(value, warnings[i].name)) {
|
||||
ok = true; /* At least one action taken */
|
||||
switch (action) {
|
||||
case WID_OFF:
|
||||
warning_state[i] &= ~mask;
|
||||
break;
|
||||
case WID_ON:
|
||||
warning_state[i] |= mask;
|
||||
break;
|
||||
case WID_RESET:
|
||||
warning_state[i] &= ~mask;
|
||||
warning_state[i] |= warning_state_init[i] & mask;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
115
asm/nasm.c
115
asm/nasm.c
@@ -332,6 +332,9 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Save away the default state of warnings */
|
||||
memcpy(warning_state_init, warning_state, sizeof warning_state);
|
||||
|
||||
if (!using_debug_info) {
|
||||
/* No debug info, redirect to the null backend (empty stubs) */
|
||||
dfmt = &null_debug_form;
|
||||
@@ -390,8 +393,9 @@ int main(int argc, char **argv)
|
||||
|
||||
/* pass = 1; */
|
||||
preproc->reset(inname, 3, depend_ptr);
|
||||
memcpy(warning_on, warning_on_global,
|
||||
(ERR_WARN_MAX+1) * sizeof(bool));
|
||||
|
||||
/* Revert all warnings to the default state */
|
||||
memcpy(warning_state, warning_state_init, sizeof warning_state);
|
||||
|
||||
while ((line = preproc->getline())) {
|
||||
/*
|
||||
@@ -624,7 +628,6 @@ static bool process_arg(char *p, char *q, int pass)
|
||||
char *param;
|
||||
int i;
|
||||
bool advance = false;
|
||||
bool do_warn;
|
||||
|
||||
if (!p || !p[0])
|
||||
return false;
|
||||
@@ -803,24 +806,28 @@ static bool process_arg(char *p, char *q, int pass)
|
||||
" -X<format> specifies error reporting format (gnu or vc)\n"
|
||||
" -w+foo enables warning foo (equiv. -Wfoo)\n"
|
||||
" -w-foo disable warning foo (equiv. -Wno-foo)\n\n"
|
||||
" -h show invocation summary and exit\n\n"
|
||||
" -w[+-]error[=foo] can be used to promote warnings to errors\n"
|
||||
" -h show invocation summary and exit\n\n"
|
||||
"--prefix,--postfix\n"
|
||||
" this options prepend or append the given argument to all\n"
|
||||
" extern and global variables\n"
|
||||
"Warnings:\n");
|
||||
for (i = 0; i <= ERR_WARN_MAX; i++)
|
||||
printf(" %-23s %s (default %s)\n",
|
||||
" these options prepend or append the given string\n"
|
||||
" to all extern and global variables\n"
|
||||
"\n"
|
||||
"Response files should contain command line parameters,\n"
|
||||
"one per line.\n"
|
||||
"\n"
|
||||
"Warnings for the -W/-w options:\n");
|
||||
for (i = 0; i <= ERR_WARN_ALL; i++)
|
||||
printf(" %-23s %s%s\n",
|
||||
warnings[i].name, warnings[i].help,
|
||||
warnings[i].enabled ? "on" : "off");
|
||||
printf
|
||||
("\nresponse files should contain command line parameters"
|
||||
", one per line.\n");
|
||||
i == ERR_WARN_ALL ? "\n" :
|
||||
warnings[i].enabled ? " (default on)" :
|
||||
" (default off)");
|
||||
if (p[2] == 'f') {
|
||||
printf("\nvalid output formats for -f are"
|
||||
printf("valid output formats for -f are"
|
||||
" (`*' denotes default):\n");
|
||||
ofmt_list(ofmt, stdout);
|
||||
} else {
|
||||
printf("\nFor a list of valid output formats, use -hf.\n");
|
||||
printf("For a list of valid output formats, use -hf.\n");
|
||||
printf("For a list of debug formats, use -f <form> -y.\n");
|
||||
}
|
||||
exit(0); /* never need usage message here */
|
||||
@@ -853,48 +860,15 @@ static bool process_arg(char *p, char *q, int pass)
|
||||
preproc = &preproc_nop;
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
case 'W':
|
||||
if (pass == 2) {
|
||||
if (param[0] == 'n' && param[1] == 'o' && param[2] == '-') {
|
||||
do_warn = false;
|
||||
param += 3;
|
||||
} else {
|
||||
do_warn = true;
|
||||
if (!set_warning_status(param)) {
|
||||
nasm_error(ERR_WARNING|ERR_NOFILE|ERR_WARN_UNK_WARNING,
|
||||
"unknown warning option: %s", param);
|
||||
}
|
||||
goto set_warning;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
if (pass == 2) {
|
||||
if (param[0] != '+' && param[0] != '-') {
|
||||
nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
|
||||
"invalid option to `-w'");
|
||||
break;
|
||||
}
|
||||
do_warn = (param[0] == '+');
|
||||
param++;
|
||||
goto set_warning;
|
||||
}
|
||||
break;
|
||||
|
||||
set_warning:
|
||||
for (i = 0; i <= ERR_WARN_MAX; i++) {
|
||||
if (!nasm_stricmp(param, warnings[i].name))
|
||||
break;
|
||||
}
|
||||
if (i <= ERR_WARN_MAX) {
|
||||
warning_on_global[i] = do_warn;
|
||||
} else if (!nasm_stricmp(param, "all")) {
|
||||
for (i = 1; i <= ERR_WARN_MAX; i++)
|
||||
warning_on_global[i] = do_warn;
|
||||
} else if (!nasm_stricmp(param, "none")) {
|
||||
for (i = 1; i <= ERR_WARN_MAX; i++)
|
||||
warning_on_global[i] = !do_warn;
|
||||
} else {
|
||||
/* Ignore invalid warning names; forward compatibility */
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case 'M':
|
||||
if (pass == 2) {
|
||||
@@ -1130,8 +1104,11 @@ static void parse_cmdline(int argc, char **argv, int pass)
|
||||
|
||||
*inname = *outname = *listname = *errname = '\0';
|
||||
|
||||
for (i = 0; i <= ERR_WARN_MAX; i++)
|
||||
warning_on_global[i] = warnings[i].enabled;
|
||||
/* Initialize all the warnings to their default state */
|
||||
for (i = 0; i < ERR_WARN_ALL; i++) {
|
||||
warning_state_init[i] = warning_state[i] =
|
||||
warnings[i].enabled ? WARN_ST_ENABLED : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* First, process the NASMENV environment variable.
|
||||
@@ -1246,7 +1223,9 @@ static void assemble_file(char *fname, StrList **depend_ptr)
|
||||
offsets = raa_init();
|
||||
}
|
||||
preproc->reset(fname, pass1, pass1 == 2 ? depend_ptr : NULL);
|
||||
memcpy(warning_on, warning_on_global, (ERR_WARN_MAX+1) * sizeof(bool));
|
||||
|
||||
/* Revert all warnings to the default state */
|
||||
memcpy(warning_state, warning_state_init, sizeof warning_state);
|
||||
|
||||
globallineno = 0;
|
||||
if (passn == 1)
|
||||
@@ -1571,17 +1550,13 @@ static void nasm_verror_vc(int severity, const char *fmt, va_list ap)
|
||||
/*
|
||||
* check to see if this is a suppressable warning
|
||||
*/
|
||||
static inline bool is_suppressable_warning(int severity)
|
||||
static inline bool is_valid_warning(int severity)
|
||||
{
|
||||
int index;
|
||||
|
||||
/* Not a warning at all */
|
||||
if ((severity & ERR_MASK) != ERR_WARNING)
|
||||
return false;
|
||||
|
||||
index = WARN_IDX(severity);
|
||||
|
||||
return index && index <= ERR_WARN_MAX;
|
||||
return WARN_IDX(severity) < ERR_WARN_ALL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1595,8 +1570,16 @@ static inline bool is_suppressable_warning(int severity)
|
||||
static bool is_suppressed_warning(int severity)
|
||||
{
|
||||
/* Might be a warning but suppresed explicitly */
|
||||
if (is_suppressable_warning(severity))
|
||||
return !warning_on[WARN_IDX(severity)];
|
||||
if (is_valid_warning(severity))
|
||||
return !(warning_state[WARN_IDX(severity)] & WARN_ST_ENABLED);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool warning_is_error(int severity)
|
||||
{
|
||||
if (is_valid_warning(severity))
|
||||
return !!(warning_state[WARN_IDX(severity)] & WARN_ST_ERROR);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
@@ -1654,7 +1637,7 @@ static void nasm_verror_common(int severity, const char *fmt, va_list args)
|
||||
}
|
||||
|
||||
vsnprintf(msg, sizeof msg - 64, fmt, args);
|
||||
if (is_suppressable_warning(severity)) {
|
||||
if (is_valid_warning(severity) && WARN_IDX(severity) != ERR_WARN_OTHER) {
|
||||
char *p = strchr(msg, '\0');
|
||||
snprintf(p, 64, " [-w+%s]", warnings[WARN_IDX(severity)].name);
|
||||
}
|
||||
@@ -1683,7 +1666,7 @@ static void nasm_verror_common(int severity, const char *fmt, va_list args)
|
||||
break;
|
||||
case ERR_WARNING:
|
||||
/* Treat warnings as errors */
|
||||
if (warning_on[WARN_IDX(ERR_WARN_TERM)])
|
||||
if (warning_is_error(severity))
|
||||
terminate_after_phase = true;
|
||||
break;
|
||||
case ERR_NONFATAL:
|
||||
|
Reference in New Issue
Block a user