[Nasm-bugs] [Bug 3392535] Duplicate label with same value is silently ignored

noreply-nasm at gorcunov.org noreply-nasm at gorcunov.org
Tue Dec 11 05:37:55 PST 2018


https://bugzilla.nasm.us/show_bug.cgi?id=3392535

C. Masloch <pushbx at 38.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|CLOSED                      |OPEN
         Resolution|REJECTED                    |---
                 CC|                            |pushbx at 38.de

--- Comment #4 from C. Masloch <pushbx at 38.de> ---
Here's a patch atop the current nasm-2.14.xx branch (commit
54aac9d3c1b501050e6e75823317a4e34d6b2066) that adds a suppressible, default-off
warning for label redefinition with same value:

diff --git a/asm/error.c b/asm/error.c
index 73db7443..3205c729 100644
--- a/asm/error.c
+++ b/asm/error.c
@@ -70,6 +70,7 @@ const struct warning warnings[ERR_WARN_ALL+1] = {
     {"unknown-warning", "unknown warning in -W/-w or warning directive",
false},
     {"negative-rep", "regative %rep count", true},
     {"phase", "phase error during stabilization", false},
+    {"label-redef", "label redefined with same value", false},

     /* THIS ENTRY MUST COME LAST */
     {"all", "all possible warnings", false}
diff --git a/asm/labels.c b/asm/labels.c
index a073f798..f29ae157 100644
--- a/asm/labels.c
+++ b/asm/labels.c
@@ -521,6 +521,23 @@ void define_label(const char *label, int32_t segment,
                        lptr->defn.label,
                        created ? "defined" : "changed");
         }
+    } else if (lastdef && lastdef == lpass) {
+        int32_t saved_line = 0;
+        const char *saved_fname = NULL;
+
+        /*
+         * Defined elsewhere in the program, seen in this pass, no change.
+         */
+        nasm_error(ERR_WARNING | ERR_WARN_LABEL_REDEF | ERR_PASS2,
+                   "label `%s' redefined with same value",
+                   lptr->defn.label);
+
+        src_get(&saved_line, &saved_fname);
+        src_set(lptr->defn.def_line, lptr->defn.def_file);
+        nasm_error(ERR_NOTE | ERR_WARN_LABEL_REDEF | ERR_PASS2,
+                   "label `%s' originally defined here",
+                   lptr->defn.label);
+        src_set(saved_line, saved_fname);
     }

     lptr->defn.segment = segment;
diff --git a/asm/nasm.c b/asm/nasm.c
index d1a4fe0d..9811ee76 100644
--- a/asm/nasm.c
+++ b/asm/nasm.c
@@ -1805,7 +1805,12 @@ static void nasm_verror_vc(int severity, const char
*fmt, va_list ap)
 static inline bool is_valid_warning(int severity)
 {
     /* Not a warning at all */
-    if ((severity & ERR_MASK) != ERR_WARNING)
+    if ((severity & ERR_MASK) != ERR_WARNING &&
+        /*
+         * ERR_NOTE is only subject to being treated like a warning
+         * if a warning index other than 0 (other) is given.
+         */
+        ((severity & ERR_MASK) != ERR_NOTE || WARN_IDX(severity) == 0))
         return false;

     return WARN_IDX(severity) < ERR_WARN_ALL;
diff --git a/include/error.h b/include/error.h
index f7e38af3..af29fd37 100644
--- a/include/error.h
+++ b/include/error.h
@@ -115,9 +115,10 @@ static inline vefunc nasm_set_verror(vefunc ve)
 #define ERR_WARN_UNK_WARNING   WARN(20) /* unknown warning */
 #define ERR_WARN_NEG_REP       WARN(21) /* negative repeat count */
 #define ERR_WARN_PHASE         WARN(22) /* phase error in pass 1 */
+#define ERR_WARN_LABEL_REDEF   WARN(23) /* label redefined with same value */

 /* The "all" warning acts as a global switch, it must come last */
-#define ERR_WARN_ALL            23 /* Do not use WARN() here */
+#define ERR_WARN_ALL            24 /* Do not use WARN() here */

 struct warning {
     const char *name;

-- 
You are receiving this mail because:
You are on the CC list for the bug.
You are watching all bug changes.


More information about the Nasm-bugs mailing list