Browse Source

* if the size of an operand is not explicitly forced in intel assembler
(e.g. via "dword ptr"), let the size of accessed fields in memory
expressions override the default size (mantis #18019)

git-svn-id: trunk@22250 -

Jonas Maebe 13 năm trước cách đây
mục cha
commit
68d9e95120
3 tập tin đã thay đổi với 75 bổ sung0 xóa
  1. 1 0
      .gitattributes
  2. 1 0
      compiler/x86/rax86int.pas
  3. 73 0
      tests/webtbs/tw18019.pp

+ 1 - 0
.gitattributes

@@ -12576,6 +12576,7 @@ tests/webtbs/tw17986.pp svneol=native#text/pascal
 tests/webtbs/tw17998.pp svneol=native#text/plain
 tests/webtbs/tw18009.pp svneol=native#text/pascal
 tests/webtbs/tw18013.pp svneol=native#text/plain
+tests/webtbs/tw18019.pp svneol=native#text/plain
 tests/webtbs/tw18075.pp svneol=native#text/pascal
 tests/webtbs/tw18082.pp svneol=native#text/plain
 tests/webtbs/tw18085.pp svneol=native#text/pascal

+ 1 - 0
compiler/x86/rax86int.pas

@@ -1296,6 +1296,7 @@ Unit Rax86int;
                         OPR_REFERENCE :
                           inc(oper.opr.ref.offset,l);
                       end;
+                      oper.SetSize(k,false);
                     end;
                    if GotOffset then
                     begin

+ 73 - 0
tests/webtbs/tw18019.pp

@@ -0,0 +1,73 @@
+{ %cpu=i386 }
+{ %opt=-Cg- }
+
+  (*$ifdef FPC *)
+    (*$z1*)
+    (*$mode delphi *)
+    (*$packset 1 *)
+    (*$asmmode intel *)
+  (*$endif *)
+  (*$apptype console *)
+
+  program asm_test;
+  type
+    tr=packed record
+      case integer of
+      1: (bytes: array [0..31] of byte);
+      2: (a,b,c,d,e,f,g,h: byte);
+      3: (aa,bb,cc,dd: word);
+    end;
+
+  var
+    r: tr;
+
+  function check_byte:boolean;
+  asm
+    cmp [r.a],0
+    setnz al
+  end;
+
+  function check_byte_as_dword:boolean;
+  asm
+    // the dword ptr has to override the size of the field declaration
+    cmp dword ptr [r.a],0
+    setnz al
+  end;
+
+
+  function check_word:boolean;
+  asm
+    cmp [r.aa],0
+    setnz al
+  end;
+
+
+  function check_word_as_dword:boolean;
+  asm
+    // the dword ptr has to override the size of the field declaration
+    cmp dword ptr [r.aa],0
+    setnz al
+  end;
+
+
+  begin
+    fillchar(r,sizeof(r),#$ff);
+    r.a:=0;
+    if check_byte then
+      halt(1);
+    if not check_byte_as_dword then
+      halt(2);
+    r.aa:=0;
+    if check_word then
+      halt(3);
+    if not check_word_as_dword then
+      halt(4);
+    fillchar(r,sizeof(r),#$ff);
+    r.a:=1;
+    if not check_byte then
+      halt(5);
+    r.aa:=1;
+    if not check_word then
+      halt(6);
+  end.
+