From: Peter Johnson Date: Thu, 1 Nov 2001 02:34:54 +0000 (-0000) Subject: Fix errors found in expr_level_op() and checkea_calc_displen() by new test X-Git-Tag: v0.1.0~222 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=00788fa80c52d3d8683fff6b2216bd59ad2acbdd;p=yasm Fix errors found in expr_level_op() and checkea_calc_displen() by new test cases. svn path=/trunk/yasm/; revision=308 --- diff --git a/libyasm/expr.c b/libyasm/expr.c index 4c2a6dc4..938a6b2c 100644 --- a/libyasm/expr.c +++ b/libyasm/expr.c @@ -564,7 +564,11 @@ expr_level_op(expr *e, int fold_const, int simplify_ident) /* copy operand if it changed places */ if (o == first_int_term) o--; - e->terms[o--] = e->terms[i]; + e->terms[o] = e->terms[i]; + /* If we moved the first_int_term, change first_int_num too */ + if (i == first_int_term) + first_int_term = o; + o--; } } @@ -1111,7 +1115,11 @@ checkea_calc_displen(expr **ep, int wordsize, int noreg, int isbpreg, * when we output). */ case 1: - *modrm |= 0100; + /* TODO: Add optional warning here about byte not being valid + * override in noreg case. + */ + if (!noreg) + *modrm |= 0100; *v_modrm = 1; break; case 2: @@ -1121,7 +1129,11 @@ checkea_calc_displen(expr **ep, int wordsize, int noreg, int isbpreg, _("invalid effective address (displacement size)")); return 0; } - *modrm |= 0200; + /* TODO: Add optional warning here about 2/4 not being valid + * override in noreg case. + */ + if (!noreg) + *modrm |= 0200; *v_modrm = 1; break; default: diff --git a/modules/arch/x86/expr.c b/modules/arch/x86/expr.c index 4c2a6dc4..938a6b2c 100644 --- a/modules/arch/x86/expr.c +++ b/modules/arch/x86/expr.c @@ -564,7 +564,11 @@ expr_level_op(expr *e, int fold_const, int simplify_ident) /* copy operand if it changed places */ if (o == first_int_term) o--; - e->terms[o--] = e->terms[i]; + e->terms[o] = e->terms[i]; + /* If we moved the first_int_term, change first_int_num too */ + if (i == first_int_term) + first_int_term = o; + o--; } } @@ -1111,7 +1115,11 @@ checkea_calc_displen(expr **ep, int wordsize, int noreg, int isbpreg, * when we output). */ case 1: - *modrm |= 0100; + /* TODO: Add optional warning here about byte not being valid + * override in noreg case. + */ + if (!noreg) + *modrm |= 0100; *v_modrm = 1; break; case 2: @@ -1121,7 +1129,11 @@ checkea_calc_displen(expr **ep, int wordsize, int noreg, int isbpreg, _("invalid effective address (displacement size)")); return 0; } - *modrm |= 0200; + /* TODO: Add optional warning here about 2/4 not being valid + * override in noreg case. + */ + if (!noreg) + *modrm |= 0200; *v_modrm = 1; break; default: diff --git a/modules/arch/x86/x86expr.c b/modules/arch/x86/x86expr.c index 4c2a6dc4..938a6b2c 100644 --- a/modules/arch/x86/x86expr.c +++ b/modules/arch/x86/x86expr.c @@ -564,7 +564,11 @@ expr_level_op(expr *e, int fold_const, int simplify_ident) /* copy operand if it changed places */ if (o == first_int_term) o--; - e->terms[o--] = e->terms[i]; + e->terms[o] = e->terms[i]; + /* If we moved the first_int_term, change first_int_num too */ + if (i == first_int_term) + first_int_term = o; + o--; } } @@ -1111,7 +1115,11 @@ checkea_calc_displen(expr **ep, int wordsize, int noreg, int isbpreg, * when we output). */ case 1: - *modrm |= 0100; + /* TODO: Add optional warning here about byte not being valid + * override in noreg case. + */ + if (!noreg) + *modrm |= 0100; *v_modrm = 1; break; case 2: @@ -1121,7 +1129,11 @@ checkea_calc_displen(expr **ep, int wordsize, int noreg, int isbpreg, _("invalid effective address (displacement size)")); return 0; } - *modrm |= 0200; + /* TODO: Add optional warning here about 2/4 not being valid + * override in noreg case. + */ + if (!noreg) + *modrm |= 0200; *v_modrm = 1; break; default: diff --git a/src/arch/x86/expr.c b/src/arch/x86/expr.c index 4c2a6dc4..938a6b2c 100644 --- a/src/arch/x86/expr.c +++ b/src/arch/x86/expr.c @@ -564,7 +564,11 @@ expr_level_op(expr *e, int fold_const, int simplify_ident) /* copy operand if it changed places */ if (o == first_int_term) o--; - e->terms[o--] = e->terms[i]; + e->terms[o] = e->terms[i]; + /* If we moved the first_int_term, change first_int_num too */ + if (i == first_int_term) + first_int_term = o; + o--; } } @@ -1111,7 +1115,11 @@ checkea_calc_displen(expr **ep, int wordsize, int noreg, int isbpreg, * when we output). */ case 1: - *modrm |= 0100; + /* TODO: Add optional warning here about byte not being valid + * override in noreg case. + */ + if (!noreg) + *modrm |= 0100; *v_modrm = 1; break; case 2: @@ -1121,7 +1129,11 @@ checkea_calc_displen(expr **ep, int wordsize, int noreg, int isbpreg, _("invalid effective address (displacement size)")); return 0; } - *modrm |= 0200; + /* TODO: Add optional warning here about 2/4 not being valid + * override in noreg case. + */ + if (!noreg) + *modrm |= 0200; *v_modrm = 1; break; default: diff --git a/src/arch/x86/x86expr.c b/src/arch/x86/x86expr.c index 4c2a6dc4..938a6b2c 100644 --- a/src/arch/x86/x86expr.c +++ b/src/arch/x86/x86expr.c @@ -564,7 +564,11 @@ expr_level_op(expr *e, int fold_const, int simplify_ident) /* copy operand if it changed places */ if (o == first_int_term) o--; - e->terms[o--] = e->terms[i]; + e->terms[o] = e->terms[i]; + /* If we moved the first_int_term, change first_int_num too */ + if (i == first_int_term) + first_int_term = o; + o--; } } @@ -1111,7 +1115,11 @@ checkea_calc_displen(expr **ep, int wordsize, int noreg, int isbpreg, * when we output). */ case 1: - *modrm |= 0100; + /* TODO: Add optional warning here about byte not being valid + * override in noreg case. + */ + if (!noreg) + *modrm |= 0100; *v_modrm = 1; break; case 2: @@ -1121,7 +1129,11 @@ checkea_calc_displen(expr **ep, int wordsize, int noreg, int isbpreg, _("invalid effective address (displacement size)")); return 0; } - *modrm |= 0200; + /* TODO: Add optional warning here about 2/4 not being valid + * override in noreg case. + */ + if (!noreg) + *modrm |= 0200; *v_modrm = 1; break; default: diff --git a/src/expr.c b/src/expr.c index 4c2a6dc4..938a6b2c 100644 --- a/src/expr.c +++ b/src/expr.c @@ -564,7 +564,11 @@ expr_level_op(expr *e, int fold_const, int simplify_ident) /* copy operand if it changed places */ if (o == first_int_term) o--; - e->terms[o--] = e->terms[i]; + e->terms[o] = e->terms[i]; + /* If we moved the first_int_term, change first_int_num too */ + if (i == first_int_term) + first_int_term = o; + o--; } } @@ -1111,7 +1115,11 @@ checkea_calc_displen(expr **ep, int wordsize, int noreg, int isbpreg, * when we output). */ case 1: - *modrm |= 0100; + /* TODO: Add optional warning here about byte not being valid + * override in noreg case. + */ + if (!noreg) + *modrm |= 0100; *v_modrm = 1; break; case 2: @@ -1121,7 +1129,11 @@ checkea_calc_displen(expr **ep, int wordsize, int noreg, int isbpreg, _("invalid effective address (displacement size)")); return 0; } - *modrm |= 0200; + /* TODO: Add optional warning here about 2/4 not being valid + * override in noreg case. + */ + if (!noreg) + *modrm |= 0200; *v_modrm = 1; break; default: