Pārlūkot izejas kodu

* skip instructions containing a reference with a segment prefix (fixes
mantis #18113)

git-svn-id: trunk@16619 -

Jonas Maebe 14 gadi atpakaļ
vecāks
revīzija
d10f46ec59
3 mainītis faili ar 57 papildinājumiem un 0 dzēšanām
  1. 1 0
      .gitattributes
  2. 34 0
      compiler/i386/popt386.pas
  3. 22 0
      tests/webtbs/tw18113.pp

+ 1 - 0
.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

+ 34 - 0
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

+ 22 - 0
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.