]> granicus.if.org Git - yasm/commitdiff
Fix referencing of local label from line that defines nonlocal label.
authorPeter Johnson <peter@tortall.net>
Wed, 25 Mar 2009 03:40:59 +0000 (03:40 -0000)
committerPeter Johnson <peter@tortall.net>
Wed, 25 Mar 2009 03:40:59 +0000 (03:40 -0000)
Reported by: Brian Gladman

svn path=/trunk/yasm/; revision=2190

modules/parsers/nasm/nasm-parse.c
modules/parsers/nasm/tests/Makefile.inc
modules/parsers/nasm/tests/locallabel2.asm [new file with mode: 0644]
modules/parsers/nasm/tests/locallabel2.hex [new file with mode: 0644]

index 0e80b582ef8db7a21ceee436185cb3733791431e..6ec14fd0291d745ecdb72c956ddf688b84025764 100644 (file)
@@ -62,8 +62,9 @@ static void nasm_parser_directive
     (yasm_parser_nasm *parser_nasm, const char *name,
      /*@null@*/ yasm_valparamhead *valparams,
      /*@null@*/ yasm_valparamhead *objext_valparams);
+static void set_nonlocal_label(yasm_parser_nasm *parser_nasm, const char *name);
 static void define_label(yasm_parser_nasm *parser_nasm, /*@only@*/ char *name,
-                         unsigned int size, int local);
+                         unsigned int size);
 
 static void yasm_ea_set_implicit_size_segment(yasm_parser_nasm *parser_nasm,
                                               yasm_effaddr *ea, yasm_expr *e)
@@ -384,7 +385,9 @@ parse_line(yasm_parser_nasm *parser_nasm)
                 /* label alone on the line */
                 yasm_warn_set(YASM_WARN_ORPHAN_LABEL,
                     N_("label alone on a line without a colon might be in error"));
-                define_label(parser_nasm, name, 0, local);
+                if (!local)
+                    set_nonlocal_label(parser_nasm, name);
+                define_label(parser_nasm, name, 0);
                 return NULL;
             }
             if (curtok == ':')
@@ -420,12 +423,15 @@ parse_line(yasm_parser_nasm *parser_nasm)
                 get_next_token();
             }
 
+            if (!local)
+                set_nonlocal_label(parser_nasm, name);
+
             if (is_eol()) {
-                define_label(parser_nasm, name, size, local);
+                define_label(parser_nasm, name, size);
                 return NULL;
             }
             if (curtok == TIMES) {
-                define_label(parser_nasm, name, size, local);
+                define_label(parser_nasm, name, size);
                 get_next_token();
                 return parse_times(parser_nasm);
             }
@@ -435,7 +441,7 @@ parse_line(yasm_parser_nasm *parser_nasm)
                                N_("instruction expected after label"));
             if (parser_nasm->tasm && bc && !size)
                 size = yasm_bc_elem_size(bc);
-            define_label(parser_nasm, name, size, local);
+            define_label(parser_nasm, name, size);
             return bc;
         }
         default:
@@ -1439,12 +1445,9 @@ parse_expr6(yasm_parser_nasm *parser_nasm, expr_type type)
 }
 
 static void
-define_label(yasm_parser_nasm *parser_nasm, char *name, unsigned int size,
-             int local)
+set_nonlocal_label(yasm_parser_nasm *parser_nasm, const char *name)
 {
-    yasm_symrec *symrec;
-
-    if ((!parser_nasm->tasm || tasm_locals) && !local) {
+    if (!parser_nasm->tasm || tasm_locals) {
         if (parser_nasm->locallabel_base)
             yasm_xfree(parser_nasm->locallabel_base);
         parser_nasm->locallabel_base_len = strlen(name);
@@ -1452,6 +1455,12 @@ define_label(yasm_parser_nasm *parser_nasm, char *name, unsigned int size,
             yasm_xmalloc(parser_nasm->locallabel_base_len+1);
         strcpy(parser_nasm->locallabel_base, name);
     }
+}
+
+static void
+define_label(yasm_parser_nasm *parser_nasm, char *name, unsigned int size)
+{
+    yasm_symrec *symrec;
 
     if (parser_nasm->abspos)
         symrec = yasm_symtab_define_equ(p_symtab, name,
index f4589c3c41a9984705cdc7a3ca5cbd46243c7f0d..9a1d5db517d430f2b790c1a923914fa84c6885ff 100644 (file)
@@ -23,6 +23,8 @@ EXTRA_DIST += modules/parsers/nasm/tests/long.asm
 EXTRA_DIST += modules/parsers/nasm/tests/long.hex
 EXTRA_DIST += modules/parsers/nasm/tests/locallabel.asm
 EXTRA_DIST += modules/parsers/nasm/tests/locallabel.hex
+EXTRA_DIST += modules/parsers/nasm/tests/locallabel2.asm
+EXTRA_DIST += modules/parsers/nasm/tests/locallabel2.hex
 EXTRA_DIST += modules/parsers/nasm/tests/nasm-prefix.asm
 EXTRA_DIST += modules/parsers/nasm/tests/nasm-prefix.hex
 EXTRA_DIST += modules/parsers/nasm/tests/newsect.asm
diff --git a/modules/parsers/nasm/tests/locallabel2.asm b/modules/parsers/nasm/tests/locallabel2.asm
new file mode 100644 (file)
index 0000000..ea0f8c9
--- /dev/null
@@ -0,0 +1,4 @@
+nl1:
+nl2:db      .0 - nl2
+.0: db      .1 - nl2
+.1:
diff --git a/modules/parsers/nasm/tests/locallabel2.hex b/modules/parsers/nasm/tests/locallabel2.hex
new file mode 100644 (file)
index 0000000..2633481
--- /dev/null
@@ -0,0 +1,2 @@
+01 
+02