Browse Source

--- Merging r43504 into '.':
U compiler/nmat.pas
--- Recording mergeinfo for merge of r43504 into '.':
U .

git-svn-id: branches/fixes_3_2@43505 -

Jonas Maebe 5 years ago
parent
commit
afa7c478a2
2 changed files with 20 additions and 6 deletions
  1. 19 5
      compiler/nmat.pas
  2. 1 1
      compiler/x86/cgx86.pas

+ 19 - 5
compiler/nmat.pas

@@ -706,17 +706,31 @@ implementation
             if is_constintnode(left) then
                begin
                  lvalue:=tordconstnode(left).value;
+                 { shl/shr are unsigned operations, so cut off upper bits }
+                 case resultdef.size of
+                   1:
+                     lvalue:=lvalue and byte($ff);
+                   2:
+                     lvalue:=lvalue and word($ffff);
+                   4:
+                     lvalue:=lvalue and dword($ffffffff);
+                   8:
+                     lvalue:=lvalue and qword($ffffffffffffffff);
+                   else
+                     internalerror(2013122301);
+                 end;
                  case nodetype of
                     shrn:
-                      lvalue:=tordconstnode(left).value shr rvalue;
+                      lvalue:=lvalue shr rvalue;
                     shln:
-                      lvalue:=tordconstnode(left).value shl rvalue;
+                      lvalue:=lvalue shl rvalue;
                     else
                       internalerror(2019050517);
                  end;
-                 if forinline then
+                 { discard shifted-out bits (shl never triggers overflow/range errors) }
+                 if forinline and
+                    (nodetype=shln) then
                    begin
-                     { shl/shr are unsigned operations, so cut off upper bits }
                      case resultdef.size of
                        1:
                          lvalue:=lvalue and byte($ff);
@@ -727,7 +741,7 @@ implementation
                        8:
                          lvalue:=lvalue and qword($ffffffffffffffff);
                        else
-                         internalerror(2013122301);
+                         internalerror(2019111701);
                      end;
                    end;
                  result:=create_simplified_ord_const(lvalue,resultdef,forinline,false);

+ 1 - 1
compiler/x86/cgx86.pas

@@ -3430,7 +3430,7 @@ unit cgx86;
             list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_ECX));
             list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EBX));
             list.concat(Taicpu.Op_reg(A_PUSH,S_L,NR_EAX));
-            inc(stackmisalignment,4*2+6*8);
+            inc(stackmisalignment,4*2+6*4);
           end;
 {$endif i386}