From 843cbf7485a6484b3948c37a0f568acdffa2ddd9 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sat, 27 Mar 2004 03:14:52 +0000 Subject: [PATCH] Fix indexreg handling in x86_expr_checkea_getregusage() to correctly handle a non-multiplier used after a multiplier (e.g. edi*8+eax). Previously, this resulted in the eax overriding the edi as the indexreg, causing the effective address not to be recognized. Update the effaddr testcase to test this case and a few other similar ones. Bugzilla bug: 31 Reported by: vclaudepierre@tiscali.fr svn path=/trunk/yasm/; revision=1106 --- modules/arch/x86/tests/effaddr.asm | 10 +++++++ modules/arch/x86/tests/effaddr.hex | 47 ++++++++++++++++++++++++++++++ modules/arch/x86/x86expr.c | 14 +++++++-- 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/modules/arch/x86/tests/effaddr.asm b/modules/arch/x86/tests/effaddr.asm index aff78669..7fa2f678 100644 --- a/modules/arch/x86/tests/effaddr.asm +++ b/modules/arch/x86/tests/effaddr.asm @@ -1,6 +1,16 @@ [bits 32] mov ax,[eax+ebx+ecx-eax] mov ax,[eax+ecx+ebx-eax] +lea edi,[edi*8+eax+label] +lea edi,[eax+edi*8+label] +mov eax,[eax*2] +mov eax,[nosplit eax*2] +mov eax,[esi+ebp] +mov eax,[ebp+esi] +mov eax,[esi*1+ebp] +mov eax,[ebp*1+esi] +mov eax,[byte eax] +mov eax,[dword eax] label dd 5 label2 diff --git a/modules/arch/x86/tests/effaddr.hex b/modules/arch/x86/tests/effaddr.hex index de1b74fc..75ad22b6 100644 --- a/modules/arch/x86/tests/effaddr.hex +++ b/modules/arch/x86/tests/effaddr.hex @@ -6,6 +6,53 @@ 8b 04 19 +8d +bc +f8 +37 +00 +00 +00 +8d +bc +f8 +37 +00 +00 +00 +8b +04 +00 +8b +04 +45 +00 +00 +00 +00 +8b +04 +2e +8b +44 +35 +00 +8b +44 +35 +00 +8b +04 +2e +8b +40 +00 +8b +80 +00 +00 +00 +00 05 00 00 diff --git a/modules/arch/x86/x86expr.c b/modules/arch/x86/x86expr.c index 653183de..efbaca97 100644 --- a/modules/arch/x86/x86expr.c +++ b/modules/arch/x86/x86expr.c @@ -260,6 +260,8 @@ x86_expr_checkea_getregusage(yasm_expr **ep, /*@null@*/ int *indexreg, int i; int *reg; int regnum; + int indexval = 0; + int indexmult = 0; yasm_expr *e; /*@-unqualifiedtrans@*/ @@ -333,8 +335,12 @@ x86_expr_checkea_getregusage(yasm_expr **ep, /*@null@*/ int *indexreg, if (!reg) return 1; (*reg)++; - if (indexreg) + /* Let last, largest multipler win indexreg */ + if (indexreg && *reg > 0 && indexval <= *reg && + !indexmult) { *indexreg = regnum; + indexval = *reg; + } } else if (e->terms[i].type == YASM_EXPR_EXPR) { /* Already ordered from ADD above, just grab the value. * Sanity check for EXPR_INT. @@ -351,8 +357,12 @@ x86_expr_checkea_getregusage(yasm_expr **ep, /*@null@*/ int *indexreg, return 1; (*reg) += yasm_intnum_get_int( e->terms[i].data.expn->terms[1].data.intn); - if (indexreg && *reg > 0) + /* Let last, largest multipler win indexreg */ + if (indexreg && *reg > 0 && indexval <= *reg) { *indexreg = regnum; + indexval = *reg; + indexmult = 1; + } } } } -- 2.40.0