瀏覽代碼

+ simplify "x mod -1", resolves #37449

git-svn-id: trunk@45969 -
florian 5 年之前
父節點
當前提交
42f2e5f8ad
共有 3 個文件被更改,包括 15 次插入1 次删除
  1. 1 0
      .gitattributes
  2. 8 1
      compiler/nmat.pas
  3. 6 0
      tests/webtbs/tw37449.pp

+ 1 - 0
.gitattributes

@@ -18391,6 +18391,7 @@ tests/webtbs/tw37398.pp svneol=native#text/pascal
 tests/webtbs/tw37400.pp svneol=native#text/pascal
 tests/webtbs/tw3742.pp svneol=native#text/plain
 tests/webtbs/tw37427.pp svneol=native#text/pascal
+tests/webtbs/tw37449.pp svneol=native#text/pascal
 tests/webtbs/tw3751.pp svneol=native#text/plain
 tests/webtbs/tw3758.pp svneol=native#text/plain
 tests/webtbs/tw3764.pp svneol=native#text/plain

+ 8 - 1
compiler/nmat.pas

@@ -154,7 +154,14 @@ implementation
                  Message(cg_e_mod_only_defined_for_pos_quotient);
                  { recover }
                  tordconstnode(right).value := 1;
-               end;
+               end
+            else if (rv=-1) and
+              (nodetype=modn) then
+              begin
+                result:=cordconstnode.create(0,left.resultdef,true);
+                left:=nil;
+                exit;
+              end;
           end;
 
         if is_constintnode(right) and is_constintnode(left) then

+ 6 - 0
tests/webtbs/tw37449.pp

@@ -0,0 +1,6 @@
+{ %OPT=-O- }
+var x:integer;
+begin
+    x := 1;
+    x := x mod -1; { buggy }
+end.