From: Peter Johnson Date: Tue, 4 Dec 2007 05:58:54 +0000 (-0000) Subject: Fix #124: Fully simplify out sym-sym in values (e.g. a symbol minus itself). X-Git-Tag: v0.7.0~39 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f938cbd21d4df71780620d620b79dfe4ae353928;p=yasm Fix #124: Fully simplify out sym-sym in values (e.g. a symbol minus itself). This could particularly cause false errors if sym is external. svn path=/trunk/yasm/; revision=2018 --- diff --git a/libyasm/tests/Makefile.inc b/libyasm/tests/Makefile.inc index e0e3d951..4b9eb1d6 100644 --- a/libyasm/tests/Makefile.inc +++ b/libyasm/tests/Makefile.inc @@ -75,6 +75,9 @@ EXTRA_DIST += libyasm/tests/unary.asm EXTRA_DIST += libyasm/tests/unary.hex EXTRA_DIST += libyasm/tests/value-err.asm EXTRA_DIST += libyasm/tests/value-err.errwarn +EXTRA_DIST += libyasm/tests/value-samesym.asm +EXTRA_DIST += libyasm/tests/value-samesym.errwarn +EXTRA_DIST += libyasm/tests/value-samesym.hex check_PROGRAMS += bitvect_test check_PROGRAMS += floatnum_test diff --git a/libyasm/tests/value-samesym.asm b/libyasm/tests/value-samesym.asm new file mode 100644 index 00000000..da325992 --- /dev/null +++ b/libyasm/tests/value-samesym.asm @@ -0,0 +1,2 @@ +extern RW +mov [eax + (RW + 22032) - (RW + 23056)], eax diff --git a/libyasm/tests/value-samesym.errwarn b/libyasm/tests/value-samesym.errwarn new file mode 100644 index 00000000..58c850b3 --- /dev/null +++ b/libyasm/tests/value-samesym.errwarn @@ -0,0 +1 @@ +-:1: warning: binary object format does not support extern variables diff --git a/libyasm/tests/value-samesym.hex b/libyasm/tests/value-samesym.hex new file mode 100644 index 00000000..4bab16b8 --- /dev/null +++ b/libyasm/tests/value-samesym.hex @@ -0,0 +1,8 @@ +67 +66 +89 +80 +00 +fc +ff +ff diff --git a/libyasm/value.c b/libyasm/value.c index e3eda5fd..74b793bc 100644 --- a/libyasm/value.c +++ b/libyasm/value.c @@ -208,6 +208,29 @@ value_finalize_scan(yasm_value *value, yasm_expr *e, continue; } + /* Look for the same symrec term; even if both are external, + * they should cancel out. + */ + for (j=0; jnumterms; j++) { + if (e->terms[j].type == YASM_EXPR_SYM + && e->terms[j].data.sym == sym + && (used & (1<terms[i].type = YASM_EXPR_INT; + e->terms[i].data.intn = yasm_intnum_create_uint(0); + e->terms[j].type = YASM_EXPR_INT; + e->terms[j].data.intn = yasm_intnum_create_uint(0); + + break; /* stop looking */ + } + } + if (j != e->numterms) + continue; + if (!yasm_symrec_get_label(sym, &precbc)) { if (value_finalize_scan(value, sube, expr_precbc, ssym_not_ok))