Просмотр исходного кода

* avoid range check errors when inlining not-nodes (mantis #21029)

git-svn-id: trunk@20046 -
Jonas Maebe 13 лет назад
Родитель
Сommit
3b8ae840c1
3 измененных файлов с 26 добавлено и 2 удалено
  1. 1 0
      .gitattributes
  2. 13 2
      compiler/nmat.pas
  3. 12 0
      tests/webtbs/tw21029.pp

+ 1 - 0
.gitattributes

@@ -12112,6 +12112,7 @@ tests/webtbs/tw20962.pp svneol=native#text/plain
 tests/webtbs/tw20995a.pp svneol=native#text/pascal
 tests/webtbs/tw20995b.pp svneol=native#text/pascal
 tests/webtbs/tw20998.pp svneol=native#text/pascal
+tests/webtbs/tw21029.pp svneol=native#text/plain
 tests/webtbs/tw2109.pp svneol=native#text/plain
 tests/webtbs/tw2110.pp svneol=native#text/plain
 tests/webtbs/tw2128.pp svneol=native#text/plain

+ 13 - 2
compiler/nmat.pas

@@ -1003,10 +1003,21 @@ implementation
                else
                  CGMessage(type_e_mismatch);
              end;
-             if not forinline then
+             { not-nodes are not range checked by the code generator -> also
+               don't range check while inlining; the resultdef is a bit tricky
+               though: the node's resultdef gets changed in most cases compared
+               to left, but the not-operation itself is caried out in the code
+               generator using the size of left
+               }
+             if not(forinline) then
                t:=cordconstnode.create(v,def,false)
              else
-               t:=create_simplified_ord_const(v,resultdef,true);
+               begin
+                 { cut off the value if necessary }
+                 t:=cordconstnode.create(v,left.resultdef,false);
+                 { now convert to node's resultdef }
+                 inserttypeconv_explicit(t,def);
+               end;
              result:=t;
              exit;
           end;

+ 12 - 0
tests/webtbs/tw21029.pp

@@ -0,0 +1,12 @@
+{$r+}
+{$inline on}
+
+function F(y : byte) : byte; inline;
+begin
+  f:=byte(not y);
+end;
+
+BEGIN
+  if F(1)<>254 then
+    halt(1);
+END.