diff options
author | H. Peter Anvin (Intel) <hpa@zytor.com> | 2018-12-12 16:49:07 -0800 |
---|---|---|
committer | H. Peter Anvin (Intel) <hpa@zytor.com> | 2018-12-12 16:49:07 -0800 |
commit | 950dee9edc475ae37d80e88b7048b8ff01d49a5f (patch) | |
tree | 9d19d3115dccc7ac9b5764ed35db307df11f6dee | |
parent | 46016cb3688bf8582f47967e09b06b69ea271e75 (diff) | |
download | nasm-950dee9edc475ae37d80e88b7048b8ff01d49a5f.tar.gz |
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>
-rw-r--r-- | asm/error.c | 2 | ||||
-rw-r--r-- | asm/labels.c | 54 | ||||
-rw-r--r-- | include/error.h | 7 |
3 files changed, 37 insertions, 26 deletions
diff --git a/asm/error.c b/asm/error.c index 61c89740..f6098f4c 100644 --- a/asm/error.c +++ b/asm/error.c @@ -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}, diff --git a/asm/labels.c b/asm/labels.c index a073f798..d0904ad3 100644 --- a/asm/labels.c +++ b/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; - - /* - * Defined elsewhere in the program, seen in this pass. - */ + if (lastdef == lpass) { + int32_t saved_line = 0; + const char *saved_fname = NULL; + int noteflags; + + /* + * 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; diff --git a/include/error.h b/include/error.h index cd64a497..3d2b7a1a 100644 --- a/include/error.h +++ b/include/error.h @@ -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 */ |