Browse Source

+ z80: added range checking for d in the (IX+d) and (IY+d) addressing modes in
the sdasz80 assembler writer, because sdasz80 silently truncates d to shortint
which produces broken code and hides bugs in the z80 code generator. The check
is behind ifdef, because the system unit doesn't compile, when this check is
enabled, due to bugs that were previously unnoticed. When these bugs are
fixed, the ifdef will be removed.

git-svn-id: trunk@45156 -

nickysn 5 years ago
parent
commit
6dbe1368ef
1 changed files with 9 additions and 0 deletions
  1. 9 0
      compiler/z80/agsdasz80.pas

+ 9 - 0
compiler/z80/agsdasz80.pas

@@ -405,6 +405,15 @@ unit agsdasz80;
                  ((o.ref^.base<>NR_NO) or (o.ref^.index<>NR_NO)) and
                  (o.ref^.offset<>0) then
                 begin
+{$ifdef Z80_SDASZ80_LAMENESS_WORKAROUND}
+                  { sdasz80 doesn't range check the offset d in the (IX+d) and
+                    (IY+d) addressing modes, but instead truncates it to
+                    shortint, introducing silent bugs, and prevents us from
+                    catching bugs in the code generator during compilation }
+                  if ((o.ref^.base<>NR_NO) or (o.ref^.index<>NR_NO)) and
+                     ((o.ref^.offset<-128) or (o.ref^.offset>127)) then
+                    internalerror(2020042802);
+{$endif Z80_SDASZ80_LAMENESS_WORKAROUND}
                   writer.AsmWrite(tostr(o.ref^.offset));
                   writer.AsmWrite(' (');
                   if o.ref^.base<>NR_NO then