From c3c6cea83804e7ba36b31d15ba25954ea3a5bdfd Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin (Intel)" Date: Fri, 14 Dec 2018 13:44:35 -0800 Subject: warnings: make WARN_* constant obligatory for warnings Make it an error to have ERR_WARNING without a suppression level. Signed-off-by: H. Peter Anvin (Intel) --- asm/assemble.c | 18 +++++++++--------- asm/eval.c | 6 +++--- asm/float.c | 2 +- asm/nasm.c | 9 ++++----- asm/parser.c | 6 +++--- asm/preproc.c | 40 ++++++++++++++++++++-------------------- output/outmacho.c | 12 ++++++------ 7 files changed, 46 insertions(+), 47 deletions(-) diff --git a/asm/assemble.c b/asm/assemble.c index e4f58311..c5d3f65c 100644 --- a/asm/assemble.c +++ b/asm/assemble.c @@ -1135,7 +1135,7 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits, if (pfx == P_O16) break; if (pfx != P_none) - nasm_warn(ERR_PASS2, "invalid operand size prefix"); + nasm_warn(WARN_OTHER|ERR_PASS2, "invalid operand size prefix"); else ins->prefixes[PPS_OSIZE] = P_O16; break; @@ -1147,7 +1147,7 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits, if (pfx == P_O32) break; if (pfx != P_none) - nasm_warn(ERR_PASS2, "invalid operand size prefix"); + nasm_warn(WARN_OTHER|ERR_PASS2, "invalid operand size prefix"); else ins->prefixes[PPS_OSIZE] = P_O32; break; @@ -1205,7 +1205,7 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits, nasm_nonfatal("attempt to reserve non-constant" " quantity of BSS space"); else if (ins->oprs[0].opflags & OPFLAG_FORWARD) - nasm_warn(ERR_PASS1, "forward reference in RESx " + nasm_warn(WARN_OTHER|ERR_PASS1, "forward reference in RESx " "can have unpredictable results"); else length += ins->oprs[0].offset; @@ -1484,19 +1484,19 @@ static int emit_prefix(struct out_data *data, const int bits, insn *ins) break; case R_CS: if (bits == 64) - nasm_warn(ERR_PASS2, "cs segment base generated, " + nasm_warn(WARN_OTHER|ERR_PASS2, "cs segment base generated, " "but will be ignored in 64-bit mode"); c = 0x2E; break; case R_DS: if (bits == 64) - nasm_warn(ERR_PASS2, "ds segment base generated, " + nasm_warn(WARN_OTHER|ERR_PASS2, "ds segment base generated, " "but will be ignored in 64-bit mode"); c = 0x3E; break; case R_ES: if (bits == 64) - nasm_warn(ERR_PASS2, "es segment base generated, " + nasm_warn(WARN_OTHER|ERR_PASS2, "es segment base generated, " "but will be ignored in 64-bit mode"); c = 0x26; break; @@ -1508,7 +1508,7 @@ static int emit_prefix(struct out_data *data, const int bits, insn *ins) break; case R_SS: if (bits == 64) { - nasm_warn(ERR_PASS2, "ss segment base generated, " + nasm_warn(WARN_OTHER|ERR_PASS2, "ss segment base generated, " "but will be ignored in 64-bit mode"); } c = 0x36; @@ -2513,7 +2513,7 @@ static enum ea_type process_ea(operand *input, ea *output, int bits, if (bits == 64 && ((input->type & IP_REL) == IP_REL)) { if (input->segment == NO_SEG || (input->opflags & OPFLAG_RELATIVE)) { - nasm_warn(ERR_PASS2, "absolute address can not be RIP-relative"); + nasm_warn(WARN_OTHER|ERR_PASS2, "absolute address can not be RIP-relative"); input->type &= ~IP_REL; input->type |= MEMORY; } @@ -2528,7 +2528,7 @@ static enum ea_type process_ea(operand *input, ea *output, int bits, if (eaflags & EAF_BYTEOFFS || (eaflags & EAF_WORDOFFS && input->disp_size != (addrbits != 16 ? 32 : 16))) - nasm_warn(ERR_PASS1, "displacement size ignored on absolute address"); + nasm_warn(WARN_OTHER|ERR_PASS1, "displacement size ignored on absolute address"); if (bits == 64 && (~input->type & IP_REL)) { output->sib_present = true; diff --git a/asm/eval.c b/asm/eval.c index 61052d60..f9380e9b 100644 --- a/asm/eval.c +++ b/asm/eval.c @@ -784,7 +784,7 @@ static expr *eval_strfunc(enum strfunc type) } if (rn_warn) - nasm_warn(ERR_PASS1, "character constant too long"); + nasm_warn(WARN_OTHER|ERR_PASS1, "character constant too long"); begintemp(); addtotemp(EXPR_SIMPLE, val); @@ -802,7 +802,7 @@ static int64_t eval_ifunc(int64_t val, enum ifunc func) case IFUNC_ILOG2E: case IFUNC_ILOG2W: if (!is_power2(uval)) - nasm_error((func == IFUNC_ILOG2E) ? ERR_NONFATAL : ERR_WARNING, + nasm_error((func == IFUNC_ILOG2E) ? ERR_NONFATAL : ERR_WARNING|WARN_OTHER, "ilog2 argument is not a power of two"); /* fall through */ case IFUNC_ILOG2F: @@ -942,7 +942,7 @@ static expr *expr6(void) case TOKEN_STR: tmpval = readstrnum(tokval->t_charptr, tokval->t_inttwo, &rn_warn); if (rn_warn) - nasm_warn(ERR_PASS1, "character constant too long"); + nasm_warn(WARN_OTHER|ERR_PASS1, "character constant too long"); addtotemp(EXPR_SIMPLE, tmpval); break; case TOKEN_REG: diff --git a/asm/float.c b/asm/float.c index 6d27dc9a..187b9e5e 100644 --- a/asm/float.c +++ b/asm/float.c @@ -685,7 +685,7 @@ static int to_packed_bcd(const char *str, const char *p, if (c >= '0' && c <= '9') { if (tv < 0) { if (n == 9) - nasm_warn(ERR_PASS2, "packed BCD truncated to 18 digits"); + nasm_warn(WARN_OTHER|ERR_PASS2, "packed BCD truncated to 18 digits"); tv = c-'0'; } else { if (n < 9) diff --git a/asm/nasm.c b/asm/nasm.c index 60d1bef6..d77775a4 100644 --- a/asm/nasm.c +++ b/asm/nasm.c @@ -202,7 +202,7 @@ nasm_set_limit(const char *limit, const char *valstr) } if (i > LIMIT_MAX) { if (passn == 0) - errlevel = ERR_WARNING|ERR_USAGE; + errlevel = ERR_WARNING|WARN_OTHER|ERR_USAGE; else errlevel = ERR_WARNING|ERR_PASS1|WARN_UNKNOWN_PRAGMA; nasm_error(errlevel, "unknown limit: `%s'", limit); @@ -215,7 +215,7 @@ nasm_set_limit(const char *limit, const char *valstr) val = readnum(valstr, &rn_error); if (rn_error || val < 0) { if (passn == 0) - errlevel = ERR_WARNING|ERR_USAGE; + errlevel = ERR_WARNING|WARN_OTHER|ERR_USAGE; else errlevel = ERR_WARNING|ERR_PASS1|WARN_BAD_PRAGMA; nasm_error(errlevel, "invalid limit value: `%s'", limit); @@ -1732,9 +1732,8 @@ static size_t warn_index(errflags severity) if ((severity & ERR_MASK) >= ERR_FATAL) return 0; /* Fatal errors are never suppressible */ - /* If this is a warning and no index is provided, it is WARN_OTHER */ - if ((severity & (ERR_MASK|WARN_MASK)) == ERR_WARNING) - severity |= WARN_OTHER; + /* Warnings MUST HAVE a warning category specifier! */ + nasm_assert((severity & (ERR_MASK|WARN_MASK)) != ERR_WARNING); index = WARN_IDX(severity); nasm_assert(index < WARN_IDX_ALL); diff --git a/asm/parser.c b/asm/parser.c index 62a0b171..74ea77c9 100644 --- a/asm/parser.c +++ b/asm/parser.c @@ -519,7 +519,7 @@ restart_parse: int slot = prefix_slot(tokval.t_integer); if (result->prefixes[slot]) { if (result->prefixes[slot] == tokval.t_integer) - nasm_warn(ERR_PASS1, "instruction has redundant prefixes"); + nasm_warn(WARN_OTHER|ERR_PASS1, "instruction has redundant prefixes"); else nasm_nonfatal("instruction has conflicting prefixes"); } @@ -736,7 +736,7 @@ is_expression: */ goto fail; } else /* DB ... */ if (oper_num == 0) - nasm_warn(ERR_PASS1, "no operand for data declaration"); + nasm_warn(WARN_OTHER|ERR_PASS1, "no operand for data declaration"); else result->operands = oper_num; @@ -1130,7 +1130,7 @@ is_expression: op->basereg = value->type; if (rs && (op->type & SIZE_MASK) != rs) - nasm_warn(ERR_PASS1, "register size specification ignored"); + nasm_warn(WARN_OTHER|ERR_PASS1, "register size specification ignored"); } } diff --git a/asm/preproc.c b/asm/preproc.c index 92c0bf76..ff3a567b 100644 --- a/asm/preproc.c +++ b/asm/preproc.c @@ -909,7 +909,7 @@ static Token *tokenize(char *line) p++; } if (*p != '}') - nasm_warn(ERR_PASS1, "unterminated %%{ construct"); + nasm_warn(WARN_OTHER|ERR_PASS1, "unterminated %%{ construct"); p[-1] = '\0'; if (*p) p++; @@ -997,7 +997,7 @@ static Token *tokenize(char *line) if (*p) { p++; } else { - nasm_warn(ERR_PASS1, "unterminated string"); + nasm_warn(WARN_OTHER|ERR_PASS1, "unterminated string"); /* Handling unterminated strings by UNV */ /* type = -1; */ } @@ -1911,7 +1911,7 @@ static bool if_condition(Token * tline, enum preproc_token ct) mmac = mmac->next; } if (tline && tline->next) - nasm_warn(ERR_PASS1, "trailing garbage after %%ifmacro ignored"); + nasm_warn(WARN_OTHER|ERR_PASS1, "trailing garbage after %%ifmacro ignored"); nasm_free(searching.name); j = found; break; @@ -1971,7 +1971,7 @@ iftype: if (!evalresult) return -1; if (tokval.t_type) - nasm_warn(ERR_PASS1, "trailing garbage after expression ignored"); + nasm_warn(WARN_OTHER|ERR_PASS1, "trailing garbage after expression ignored"); if (!is_simple(evalresult)) { nasm_nonfatal("non-constant value given to `%s'", pp_directives[ct]); @@ -2005,7 +2005,7 @@ static bool define_smacro(Context *ctx, const char *mname, bool casesense, if (smacro_defined(ctx, mname, nparam, &smac, casesense)) { if (!smac) { - nasm_warn(ERR_PASS1, "single-line macro `%s' defined both with and" + nasm_warn(WARN_OTHER|ERR_PASS1, "single-line macro `%s' defined both with and" " without parameters", mname); /* * Some instances of the old code considered this a failure, @@ -2515,7 +2515,7 @@ static int do_directive(Token *tline, char **output) case PP_CLEAR: if (tline->next) - nasm_warn(ERR_PASS1, "trailing garbage after `%%clear' ignored"); + nasm_warn(WARN_OTHER|ERR_PASS1, "trailing garbage after `%%clear' ignored"); free_macros(); init_macros(); free_tlist(origline); @@ -2531,7 +2531,7 @@ static int do_directive(Token *tline, char **output) return DIRECTIVE_FOUND; /* but we did _something_ */ } if (t->next) - nasm_warn(ERR_PASS1, "trailing garbage after `%%depend' ignored"); + nasm_warn(WARN_OTHER|ERR_PASS1, "trailing garbage after `%%depend' ignored"); p = t->text; if (t->type != TOK_INTERNAL_STRING) nasm_unquote_cstr(p, i); @@ -2550,7 +2550,7 @@ static int do_directive(Token *tline, char **output) return DIRECTIVE_FOUND; /* but we did _something_ */ } if (t->next) - nasm_warn(ERR_PASS1, "trailing garbage after `%%include' ignored"); + nasm_warn(WARN_OTHER|ERR_PASS1, "trailing garbage after `%%include' ignored"); p = t->text; if (t->type != TOK_INTERNAL_STRING) nasm_unquote_cstr(p, i); @@ -2592,7 +2592,7 @@ static int do_directive(Token *tline, char **output) return DIRECTIVE_FOUND; /* but we did _something_ */ } if (tline->next) - nasm_warn(ERR_PASS1, "trailing garbage after `%%use' ignored"); + nasm_warn(WARN_OTHER|ERR_PASS1, "trailing garbage after `%%use' ignored"); if (tline->type == TOK_STRING) nasm_unquote_cstr(tline->text, i); use_pkg = nasm_stdmac_find_package(tline->text); @@ -2621,7 +2621,7 @@ static int do_directive(Token *tline, char **output) return DIRECTIVE_FOUND; /* but we did _something_ */ } if (tline->next) - nasm_warn(ERR_PASS1, "trailing garbage after `%s' ignored", + nasm_warn(WARN_OTHER|ERR_PASS1, "trailing garbage after `%s' ignored", pp_directives[i]); p = nasm_strdup(tline->text); } else { @@ -2726,7 +2726,7 @@ issue_error: case COND_ELSE_TRUE: case COND_ELSE_FALSE: - nasm_warn(ERR_PASS1|ERR_PP_PRECOND, + nasm_warn(WARN_OTHER|ERR_PASS1|ERR_PP_PRECOND, "`%%elif' after `%%else' ignored"); istk->conds->state = COND_NEVER; break; @@ -2751,7 +2751,7 @@ issue_error: case PP_ELSE: if (tline->next) - nasm_warn(ERR_PASS1|ERR_PP_PRECOND, + nasm_warn(WARN_OTHER|ERR_PASS1|ERR_PP_PRECOND, "trailing garbage after `%%else' ignored"); if (!istk->conds) nasm_fatal("`%%else: no matching `%%if'"); @@ -2770,7 +2770,7 @@ issue_error: case COND_ELSE_TRUE: case COND_ELSE_FALSE: - nasm_warn(ERR_PASS1|ERR_PP_PRECOND, + nasm_warn(WARN_OTHER|ERR_PASS1|ERR_PP_PRECOND, "`%%else' after `%%else' ignored."); istk->conds->state = COND_NEVER; break; @@ -2780,7 +2780,7 @@ issue_error: case PP_ENDIF: if (tline->next) - nasm_warn(ERR_PASS1|ERR_PP_PRECOND, + nasm_warn(WARN_OTHER|ERR_PASS1|ERR_PP_PRECOND, "trailing garbage after `%%endif' ignored"); if (!istk->conds) nasm_fatal("`%%endif': no matching `%%if'"); @@ -2820,7 +2820,7 @@ issue_error: || defining->plus) && (defining->nparam_min <= mmac->nparam_max || mmac->plus)) { - nasm_warn(ERR_PASS1, "redefining multi-line macro `%s'", + nasm_warn(WARN_OTHER|ERR_PASS1, "redefining multi-line macro `%s'", defining->name); return DIRECTIVE_FOUND; } @@ -2918,7 +2918,7 @@ issue_error: if (!evalresult) return DIRECTIVE_FOUND; if (tokval.t_type) - nasm_warn(ERR_PASS1, "trailing garbage after expression ignored"); + nasm_warn(WARN_OTHER|ERR_PASS1, "trailing garbage after expression ignored"); if (!is_simple(evalresult)) { nasm_nonfatal("non-constant value given to `%%rotate'"); return DIRECTIVE_FOUND; @@ -2966,7 +2966,7 @@ issue_error: return DIRECTIVE_FOUND; } if (tokval.t_type) - nasm_warn(ERR_PASS1, "trailing garbage after expression ignored"); + nasm_warn(WARN_OTHER|ERR_PASS1, "trailing garbage after expression ignored"); if (!is_simple(evalresult)) { nasm_nonfatal("non-constant value given to `%%rep'"); return DIRECTIVE_FOUND; @@ -3163,7 +3163,7 @@ issue_error: return DIRECTIVE_FOUND; } if (tline->next) - nasm_warn(ERR_PASS1, "trailing garbage after macro name ignored"); + nasm_warn(WARN_OTHER|ERR_PASS1, "trailing garbage after macro name ignored"); /* Find the context that symbol belongs to */ ctx = get_ctx(tline->text, &mname); @@ -3295,7 +3295,7 @@ issue_error: return DIRECTIVE_FOUND; /* but we did _something_ */ } if (t->next) - nasm_warn(ERR_PASS1, "trailing garbage after `%%pathsearch' ignored"); + nasm_warn(WARN_OTHER|ERR_PASS1, "trailing garbage after `%%pathsearch' ignored"); p = t->text; if (t->type != TOK_INTERNAL_STRING) nasm_unquote(p, NULL); @@ -3554,7 +3554,7 @@ issue_error: } if (tokval.t_type) - nasm_warn(ERR_PASS1, "trailing garbage after expression ignored"); + nasm_warn(WARN_OTHER|ERR_PASS1, "trailing garbage after expression ignored"); if (!is_simple(evalresult)) { nasm_nonfatal("non-constant value given to `%%%sassign'", diff --git a/output/outmacho.c b/output/outmacho.c index 3d4767d0..820136f6 100644 --- a/output/outmacho.c +++ b/output/outmacho.c @@ -472,7 +472,7 @@ static int64_t add_reloc(struct section *sect, int32_t section, break; case RL_SUB: /* obsolete */ - nasm_error(ERR_WARNING, "relcation with subtraction" + nasm_error(ERR_WARNING|WARN_OTHER, "relcation with subtraction" "becomes to be obsolete"); r->ext = 0; r->type = X86_64_RELOC_SUBTRACTOR; @@ -559,7 +559,7 @@ static void macho_output(int32_t secto, const void *data, s = get_section_by_index(secto); if (!s) { - nasm_error(ERR_WARNING, "attempt to assemble code in" + nasm_error(ERR_WARNING|WARN_OTHER, "attempt to assemble code in" " section %d: defaulting to `.text'", secto); s = get_section_by_name("__TEXT", "__text"); @@ -581,10 +581,10 @@ static void macho_output(int32_t secto, const void *data, is_bss = (s->flags & SECTION_TYPE) == S_ZEROFILL; if (is_bss && type != OUT_RESERVE) { - nasm_error(ERR_WARNING, "attempt to initialize memory in " + nasm_error(ERR_WARNING|WARN_OTHER, "attempt to initialize memory in " "BSS section: ignored"); /* FIXME */ - nasm_error(ERR_WARNING, "section size may be negative" + nasm_error(ERR_WARNING|WARN_OTHER, "section size may be negative" "with address symbols"); s->size += realsize(type, size); return; @@ -595,7 +595,7 @@ static void macho_output(int32_t secto, const void *data, switch (type) { case OUT_RESERVE: if (!is_bss) { - nasm_error(ERR_WARNING, "uninitialized space declared in" + nasm_error(ERR_WARNING|WARN_OTHER, "uninitialized space declared in" " %s,%s section: zeroing", s->segname, s->sectname); sect_write(s, NULL, size); @@ -1655,7 +1655,7 @@ static void macho_write (void) if (seg_nsects > 0) offset = macho_write_segment (offset); else - nasm_error(ERR_WARNING, "no sections?"); + nasm_error(ERR_WARNING|WARN_OTHER, "no sections?"); if (nsyms > 0) { /* write out symbol command */ -- cgit v1.2.1