浏览代码

* correctly change the signdness information of tordconstnodes that are
simplified via typeconvnode (corrects resultdef of "qword(1) shl 33",
mantis #22133)
* simplify shl/shr nodes after their resultdef has been set, so the
resultdef used during simplify is set (fixes same expression as above
when it is calculated by an inline function)

git-svn-id: trunk@21394 -

Jonas Maebe 13 年之前
父节点
当前提交
9e0184884e
共有 4 个文件被更改,包括 41 次插入4 次删除
  1. 1 0
      .gitattributes
  2. 4 0
      compiler/ncnv.pas
  3. 4 4
      compiler/nmat.pas
  4. 32 0
      tests/webtbs/tw22133.pp

+ 1 - 0
.gitattributes

@@ -12615,6 +12615,7 @@ tests/webtbs/tw2196.pp svneol=native#text/plain
 tests/webtbs/tw2197.pp svneol=native#text/plain
 tests/webtbs/tw2198.pp svneol=native#text/plain
 tests/webtbs/tw2210.pp svneol=native#text/plain
+tests/webtbs/tw22133.pp svneol=native#text/plain
 tests/webtbs/tw2214.pp svneol=native#text/plain
 tests/webtbs/tw2220.pp svneol=native#text/plain
 tests/webtbs/tw2226.pp svneol=native#text/plain

+ 4 - 0
compiler/ncnv.pas

@@ -2699,6 +2699,10 @@ implementation
                      testrange(resultdef,tordconstnode(left).value,(nf_explicit in flags),false);
                    left.resultdef:=resultdef;
                    tordconstnode(left).typedef:=resultdef;
+                   if is_signed(resultdef) then
+                     tordconstnode(left).value.signed:=true
+                   else
+                     tordconstnode(left).value.signed:=false;
                    result:=left;
                    left:=nil;
                    exit;

+ 4 - 4
compiler/nmat.pas

@@ -590,10 +590,6 @@ implementation
               exit;
            end;
 
-         result:=simplify(false);
-         if assigned(result) then
-           exit;
-
 {$ifdef cpunodefaultint}
          { for small cpus we use the smallest common type }
          if (left.resultdef.typ=orddef) and (right.resultdef.typ=orddef) then
@@ -632,6 +628,10 @@ implementation
 {$endif cpunodefaultint}
 
          resultdef:=left.resultdef;
+
+         result:=simplify(false);
+         if assigned(result) then
+           exit;
       end;
 
 

+ 32 - 0
tests/webtbs/tw22133.pp

@@ -0,0 +1,32 @@
+program tw22133;
+
+{$mode objfpc}{$H+}
+
+type
+  uint64 = qword;
+
+var
+  T64:UInt64;
+
+//force checking constants in compile-time
+{$RANGECHECKS ON}
+
+{$inline on}
+
+function testshift(a:uint64; b: byte): uint64; inline;
+begin
+  result:=a shl b;
+end;
+
+begin
+  T64:=UInt64(1 shl 63);
+  if T64<>uint64(high(int64)+1) then
+    halt(1);
+  T64:=UInt64(1) shl 63;
+  if T64<>uint64(high(int64)+1) then
+    halt(2);
+  T64:=testshift(1,63);
+  if T64<>uint64(high(int64)+1) then
+    halt(3);
+end.
+