Explorar el Código

* Fixed handling of sign in constant expressions in Intel x86 assembler reader. Mantis #26668.

git-svn-id: trunk@28731 -
sergei hace 10 años
padre
commit
de42f2f2f7
Se han modificado 3 ficheros con 43 adiciones y 15 borrados
  1. 1 0
      .gitattributes
  2. 8 15
      compiler/x86/rax86int.pas
  3. 34 0
      tests/webtbs/tw26668.pp

+ 1 - 0
.gitattributes

@@ -14089,6 +14089,7 @@ tests/webtbs/tw26599.pp svneol=native#text/pascal
 tests/webtbs/tw26615.pp svneol=native#text/pascal
 tests/webtbs/tw26627.pp svneol=native#text/plain
 tests/webtbs/tw2666.pp svneol=native#text/plain
+tests/webtbs/tw26668.pp svneol=native#text/plain
 tests/webtbs/tw2668.pp svneol=native#text/plain
 tests/webtbs/tw2669.pp svneol=native#text/plain
 tests/webtbs/tw26749.pp svneol=native#text/pascal

+ 8 - 15
compiler/x86/rax86int.pas

@@ -65,7 +65,7 @@ Unit Rax86int;
          procedure BuildRecordOffsetSize(const expr: string;var offset:aint;var size:aint; var mangledname: string; needvmtofs: boolean);
          procedure BuildConstSymbolExpression(needofs,isref,startingminus:boolean;var value:aint;var asmsym:string;var asmsymtyp:TAsmsymtype);
          function BuildConstExpression:aint;
-         function BuildRefConstExpression:aint;
+         function BuildRefConstExpression(startingminus:boolean=false):aint;
          procedure BuildReference(oper : tx86operand);
          procedure BuildOperand(oper: tx86operand;istypecast:boolean);
          procedure BuildConstantOperand(oper: tx86operand);
@@ -1141,13 +1141,13 @@ Unit Rax86int;
       end;
 
 
-    Function tx86intreader.BuildRefConstExpression:aint;
+    Function tx86intreader.BuildRefConstExpression(startingminus:boolean):aint;
       var
         l : aint;
         hs : string;
         hssymtyp : TAsmsymtype;
       begin
-        BuildConstSymbolExpression(false,true,false,l,hs,hssymtyp);
+        BuildConstSymbolExpression(false,true,startingminus,l,hs,hssymtyp);
         if hs<>'' then
          Message(asmr_e_relocatable_symbol_not_allowed);
         BuildRefConstExpression:=l;
@@ -1190,7 +1190,8 @@ Unit Rax86int;
                    (SearchIConstant(actasmpattern,l) or
                     SearchRecordType(actasmpattern)) then
                  begin
-                   l:=BuildRefConstExpression;
+                   l:=BuildRefConstExpression(negative);
+                   negative:=false;   { "l" was negated if necessary }
                    GotPlus:=(prevasmtoken=AS_PLUS);
                    GotStar:=(prevasmtoken=AS_STAR);
                    case oper.opr.typ of
@@ -1198,23 +1199,15 @@ Unit Rax86int;
                        begin
                          if GotStar then
                            Message(asmr_e_invalid_reference_syntax);
-                         if negative then
-                           Dec(oper.opr.localsymofs,l)
-                         else
-                           Inc(oper.opr.localsymofs,l);
+                         Inc(oper.opr.localsymofs,l);
                        end;
                      OPR_REFERENCE :
                        begin
                          if GotStar then
                           oper.opr.ref.scalefactor:=l
                          else
-                          begin
-                            if negative then
-                              Dec(oper.opr.ref.offset,l)
-                            else
-                              Inc(oper.opr.ref.offset,l);
-                          end;
-                        end;
+                           Inc(oper.opr.ref.offset,l);
+                       end;
                    end;
                  end
                 else

+ 34 - 0
tests/webtbs/tw26668.pp

@@ -0,0 +1,34 @@
+{ %CPU=i386 }
+{ %OPT=-Cg- }
+
+{$mode delphi}
+const __dd = 1;
+function f1 (var p : longword) : byte;
+asm
+  lea eax, [ eax + 2 ]
+  mov al,  [eax - __dd + 1].byte
+end;
+
+function f2 (var p : longword) : byte;
+asm
+  lea eax, [ eax + 2 ]
+  mov al,  [eax - __dd].byte [1]
+end;
+
+function f3 (var p : longword) : byte;
+asm
+  lea eax, [ eax + 2 ]
+  mov al,  [eax - 1 + 1].byte
+end;
+
+var v : longword = $01020304;
+
+begin
+  { all three functions must produce the same code }
+  if f1(v)<>2 then
+    halt(1);
+  if f2(v)<>2 then
+    halt(2);
+  if f3(v)<>2 then
+    halt(3);
+end.