From d10f46ec597fbaa27fd01066afd918bc2feceb18 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Thu, 23 Dec 2010 15:24:29 +0000 Subject: [PATCH] * skip instructions containing a reference with a segment prefix (fixes mantis #18113) git-svn-id: trunk@16619 - --- .gitattributes | 1 + compiler/i386/popt386.pas | 34 ++++++++++++++++++++++++++++++++++ tests/webtbs/tw18113.pp | 22 ++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 tests/webtbs/tw18113.pp diff --git a/.gitattributes b/.gitattributes index cd53a96f31..00f3f0a322 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10907,6 +10907,7 @@ tests/webtbs/tw18075.pp svneol=native#text/pascal tests/webtbs/tw18082.pp svneol=native#text/plain tests/webtbs/tw18085.pp svneol=native#text/pascal tests/webtbs/tw18086.pp svneol=native#text/pascal +tests/webtbs/tw18113.pp svneol=native#text/plain tests/webtbs/tw18123.pp svneol=native#text/pascal tests/webtbs/tw18127.pp svneol=native#text/pascal tests/webtbs/tw18131.pp svneol=native#text/pascal diff --git a/compiler/i386/popt386.pas b/compiler/i386/popt386.pas index 3d5e6f1822..2952778919 100644 --- a/compiler/i386/popt386.pas +++ b/compiler/i386/popt386.pas @@ -128,6 +128,20 @@ begin end; +{ returns true if p contains a memory operand with a segment set } +function InsContainsSegRef(p: taicpu): boolean; +var + i: longint; +begin + result:=true; + for i:=0 to p.opercnt-1 do + if (p.oper[i]^.typ=top_ref) and + (p.oper[i]^.ref^.segment<>NR_NO) then + exit; + result:=false; +end; + + procedure PrePeepHoleOpts(asml: TAsmList; BlockStart, BlockEnd: tai); var p,hp1: tai; @@ -140,6 +154,11 @@ begin case p.Typ Of Ait_Instruction: begin + if InsContainsSegRef(taicpu(p)) then + begin + p := tai(p.next); + continue; + end; case taicpu(p).opcode Of A_IMUL: {changes certain "imul const, %reg"'s to lea sequences} @@ -606,6 +625,11 @@ begin case p.Typ Of ait_instruction: begin + if InsContainsSegRef(taicpu(p)) then + begin + p := tai(p.next); + continue; + end; { Handle Jmp Optimizations } if taicpu(p).is_jmp then begin @@ -1779,6 +1803,11 @@ begin case p.Typ Of Ait_Instruction: begin + if InsContainsSegRef(taicpu(p)) then + begin + p := tai(p.next); + continue; + end; case taicpu(p).opcode Of A_Jcc: begin @@ -2065,6 +2094,11 @@ begin case p.Typ Of Ait_Instruction: begin + if InsContainsSegRef(taicpu(p)) then + begin + p := tai(p.next); + continue; + end; case taicpu(p).opcode Of A_CALL: if (current_settings.optimizecputype < cpu_Pentium2) and diff --git a/tests/webtbs/tw18113.pp b/tests/webtbs/tw18113.pp new file mode 100644 index 0000000000..bb61963d07 --- /dev/null +++ b/tests/webtbs/tw18113.pp @@ -0,0 +1,22 @@ +{ %target=go32v2 } +{ %interactive } + +{ check whether this program writes '*' } + +Procedure Confuse; +begin + +end; + + +Procedure TestBug(chr:word); +begin +Confuse; {if you comment it, everything is fine even in Level 2} +Mem[$B800:0]:=byte(chr); +end; + +begin +writeln(#13#10#13#10); +TestBug(42); {should print '*'} +readln; +end.