From: Peter Johnson Date: Wed, 25 Mar 2009 03:40:59 +0000 (-0000) Subject: Fix referencing of local label from line that defines nonlocal label. X-Git-Tag: v0.8.0~2^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ff21f3e607c91163253b74a63e5bac433a57a0ab;p=yasm Fix referencing of local label from line that defines nonlocal label. Reported by: Brian Gladman svn path=/trunk/yasm/; revision=2190 --- diff --git a/modules/parsers/nasm/nasm-parse.c b/modules/parsers/nasm/nasm-parse.c index 0e80b582..6ec14fd0 100644 --- a/modules/parsers/nasm/nasm-parse.c +++ b/modules/parsers/nasm/nasm-parse.c @@ -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, diff --git a/modules/parsers/nasm/tests/Makefile.inc b/modules/parsers/nasm/tests/Makefile.inc index f4589c3c..9a1d5db5 100644 --- a/modules/parsers/nasm/tests/Makefile.inc +++ b/modules/parsers/nasm/tests/Makefile.inc @@ -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 index 00000000..ea0f8c92 --- /dev/null +++ b/modules/parsers/nasm/tests/locallabel2.asm @@ -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 index 00000000..26334819 --- /dev/null +++ b/modules/parsers/nasm/tests/locallabel2.hex @@ -0,0 +1,2 @@ +01 +02