mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-01-30 16:41:05 +08:00
BR 3392535: warning on redefine, promote define-on-pass2 to error
If we redefine consistently, make it a suppressed-by-default warning. If we end up doing the define on pass 2, promote that to a default-error warning; using a default-error warning allows the user to demote it should they so wish. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com> Requested-by: C. Masloch <pushbx@38.de>
This commit is contained in:
parent
46016cb368
commit
950dee9edc
@ -74,6 +74,8 @@ const struct warning warnings[WARN_ALL+1] = {
|
||||
{"unknown-warning", "unknown warning in -W/-w or warning directive", off},
|
||||
{"negative-rep", "regative %rep count", on},
|
||||
{"phase", "phase error during stabilization", off},
|
||||
{"label-redef", "label redefined to an identical value", off},
|
||||
{"label-redef-late", "label (re)defined during code generation", err},
|
||||
|
||||
/* THESE ENTRIES SHOULD COME LAST */
|
||||
{"other", "any warning not specifially mentioned above", on},
|
||||
|
52
asm/labels.c
52
asm/labels.c
@ -494,35 +494,43 @@ void define_label(const char *label, int32_t segment,
|
||||
lptr->defn.size != size;
|
||||
global_offset_changed += changed;
|
||||
|
||||
if (changed) {
|
||||
if (lastdef == lpass) {
|
||||
int32_t saved_line = 0;
|
||||
const char *saved_fname = NULL;
|
||||
if (lastdef == lpass) {
|
||||
int32_t saved_line = 0;
|
||||
const char *saved_fname = NULL;
|
||||
int noteflags;
|
||||
|
||||
/*
|
||||
* Defined elsewhere in the program, seen in this pass.
|
||||
*/
|
||||
/*
|
||||
* Defined elsewhere in the program, seen in this pass.
|
||||
*/
|
||||
if (changed) {
|
||||
nasm_error(ERR_NONFATAL,
|
||||
"label `%s' inconsistently redefined",
|
||||
lptr->defn.label);
|
||||
|
||||
src_get(&saved_line, &saved_fname);
|
||||
src_set(lptr->defn.def_line, lptr->defn.def_file);
|
||||
nasm_error(ERR_NOTE, "label `%s' originally defined here",
|
||||
noteflags = ERR_NOTE;
|
||||
} else {
|
||||
nasm_error(ERR_WARNING|WARN_LABEL_REDEF|ERR_PASS2,
|
||||
"label `%s' redefined to an identical value",
|
||||
lptr->defn.label);
|
||||
src_set(saved_line, saved_fname);
|
||||
} else if (pass0 > 1 && lptr->defn.type != LBL_SPECIAL) {
|
||||
/*
|
||||
* This probably should be ERR_NONFATAL, but not quite yet. As a
|
||||
* special case, LBL_SPECIAL symbols are allowed to be changed
|
||||
* even during the last pass.
|
||||
*/
|
||||
nasm_error(ERR_WARNING, "label `%s' %s during code generation",
|
||||
lptr->defn.label,
|
||||
created ? "defined" : "changed");
|
||||
noteflags = ERR_NOTE|WARN_LABEL_REDEF|ERR_PASS2;
|
||||
}
|
||||
}
|
||||
|
||||
src_get(&saved_line, &saved_fname);
|
||||
src_set(lptr->defn.def_line, lptr->defn.def_file);
|
||||
nasm_error(noteflags, "label `%s' originally defined here", lptr->defn.label);
|
||||
src_set(saved_line, saved_fname);
|
||||
} else if (changed && pass0 > 1 && lptr->defn.type != LBL_SPECIAL) {
|
||||
/*
|
||||
* WARN_LABEL_LATE defaults to an error, as this should never actually happen.
|
||||
* Just in case this is a backwards compatibility problem, still make it a
|
||||
* warning so that the user can suppress or demote it.
|
||||
*
|
||||
* As a special case, LBL_SPECIAL symbols are allowed to be changed
|
||||
* even during the last pass.
|
||||
*/
|
||||
nasm_error(ERR_WARNING|WARN_LABEL_LATE,
|
||||
"label `%s' %s during code generation",
|
||||
lptr->defn.label, created ? "defined" : "changed");
|
||||
}
|
||||
lptr->defn.segment = segment;
|
||||
lptr->defn.offset = offset;
|
||||
lptr->defn.size = size;
|
||||
|
@ -95,8 +95,7 @@ static inline vefunc nasm_set_verror(vefunc ve)
|
||||
#define WARN_MNP WARN( 1) /* macro-num-parameters warning */
|
||||
#define WARN_MSR WARN( 2) /* macro self-reference */
|
||||
#define WARN_MDP WARN( 3) /* macro default parameters check */
|
||||
#define WARN_OL WARN( 4) /* orphan label (no colon, and
|
||||
* alone on line) */
|
||||
#define WARN_OL WARN( 4) /* orphan label (no colon, and alone on line) */
|
||||
#define WARN_NOV WARN( 5) /* numeric overflow */
|
||||
#define WARN_GNUELF WARN( 6) /* using GNU ELF extensions */
|
||||
#define WARN_FL_OVERFLOW WARN( 7) /* FP overflow */
|
||||
@ -115,9 +114,11 @@ static inline vefunc nasm_set_verror(vefunc ve)
|
||||
#define WARN_UNK_WARNING WARN(20) /* unknown warning */
|
||||
#define WARN_NEG_REP WARN(21) /* negative repeat count */
|
||||
#define WARN_PHASE WARN(22) /* phase error in pass 1 */
|
||||
#define WARN_LABEL_REDEF WARN(23) /* label redefined, but consistent */
|
||||
#define WARN_LABEL_LATE WARN(24) /* label (re)defined during code generation */
|
||||
|
||||
/* These two should come last */
|
||||
#define WARN_ALL (22+2) /* Do not use WARN() here */
|
||||
#define WARN_ALL (24+2) /* Do not use WARN() here */
|
||||
#define WARN_OTHER WARN(WARN_ALL-1) /* any noncategorized warning */
|
||||
|
||||
/* This is a bitmask */
|
||||
|
Loading…
Reference in New Issue
Block a user