View Issue Details

IDProjectCategoryView StatusLast Update
0035180FPCOtherpublic2019-03-04 23:09
ReporterJ. Gareth MoretonAssigned ToPierre Muller 
PrioritylowSeveritytrivialReproducibilityN/A
Status resolvedResolutionfixed 
Platformx86_64-win64OSMicrosoft WindowsOS Version10 Professional
Product Version3.3.1Product Buildr41558 
Target Version3.3.1Fixed in Version3.3.1 
Summary0035180: [Patch / Test] Fixes to tests/test/cg/tmoddiv4.pp
DescriptionThis patch serves to fix range errors and test values in tmoddiv4.pp, which is meant to test div and mod operations with QWords, but because some of the constants are larger than $7FFFFFFFFFFFFFFF, they were being converted into (signed) Int64 operations instead and returning run-time errors when compiled with -Cr.

Additionally, some incorrect expected answers (at least as far as unsigned division is concerned) have been corrected.
Steps To ReproduceApply patch and confirm test correctness.
Additional InformationThe error output is also a bit more helpful now in regards to the actual calculation performed.
Tagspatch, range checks, regression, test
Fixed in Revision41589
FPCOldBugId0
FPCTarget
Attached Files
  • tmoddiv4.patch (3,430 bytes)
    Index: tests/test/cg/tmoddiv4.pp
    ===================================================================
    --- tests/test/cg/tmoddiv4.pp	(revision 41558)
    +++ tests/test/cg/tmoddiv4.pp	(working copy)
    @@ -3,6 +3,9 @@
     const
       TestValues: array[0..10] of QWord = (500, 1, 0, 995, $100000000, $100000001, $7FFFFFFFFFFFFFFF, QWord($8000000000000000), QWord($8000000000000001), QWord($8000000000000002), 1000000);
     
    +  { Divisors are only for the error reporting }
    +  Divisors: array[0..8] of QWord = (1000, 1, 3, $1000, $7FFFFFFF, $80000000, $7FFFFFFFFFFFFFFF, QWord($8000000000000000), QWord($8000000000000001));
    +
     const
       ExpectedResults: array[0..10,1..18] of QWord = (
         (0,500,500,0,166,2,0,500,0,500,0,500,0,500,0,500,0,500),
    @@ -11,10 +14,10 @@
         (0,995,995,0,331,2,0,995,0,995,0,995,0,995,0,995,0,995),
         (4294967,296,4294967296,0,1431655765,1,1048576,0,2,2,2,0,0,4294967296,0,4294967296,0,4294967296),
         (4294967,297,4294967297,0,1431655765,2,1048576,1,2,3,2,1,0,4294967297,0,4294967297,0,4294967297),
    -    (9223372036854775,807,9223372036854775807,0,3074457345618258602,1,2251799813685247,4095,4294967298,1,4294967295,2147483647,1,0,0,9223372036854775807,18446744073709551615,0),
    -    (9223372036854775,808,9223372036854775808,0,3074457345618258602,2,2251799813685248,0,4294967298,2,4294967296,0,1,1,1,0,1,18446744073709551615),
    -    (9223372036854775,809,9223372036854775809,0,3074457345618258603,0,2251799813685248,1,4294967298,3,4294967296,1,1,2,0,9223372036854775809,1,0),
    -    (9223372036854775,810,9223372036854775810,0,3074457345618258603,1,2251799813685248,2,4294967298,4,4294967296,2,1,3,0,9223372036854775810,0,9223372036854775810),
    +    (9223372036854775,807,9223372036854775807,0,3074457345618258602,1,2251799813685247,4095,4294967298,1,4294967295,2147483647,1,0,0,$7FFFFFFFFFFFFFFF,0,$7FFFFFFFFFFFFFFF),
    +    (9223372036854775,808,9223372036854775808,0,3074457345618258602,2,2251799813685248,0,4294967298,2,4294967296,0,1,1,1,0,0,QWord($8000000000000000)),
    +    (9223372036854775,809,9223372036854775809,0,3074457345618258603,0,2251799813685248,1,4294967298,3,4294967296,1,1,2,1,1,1,0),
    +    (9223372036854775,810,9223372036854775810,0,3074457345618258603,1,2251799813685248,2,4294967298,4,4294967296,2,1,3,1,2,1,1),
         (1000,0,1000000,0,333333,1,244,576,0,1000000,0,1000000,0,1000000,0,1000000,0,1000000));
     
     var
    @@ -25,7 +28,12 @@
       begin
         if Y<>ExpectedResults[C,Col] then
           begin
    -        writeln('Error at ',C,' ',Col);
    +        Write(#10'Error at ', C, ',', Col, ' - ', TestValues[C]);
    +        if (Col and $1) = 0 then
    +          Write(' mod ')
    +        else
    +          Write(' div ');
    +        WriteLn(Divisors[(Col - 1) shr 1], ' - expected ', ExpectedResults[C,Col], ' got ', Y);
             halt(1);
           end;
         Inc(Col);
    @@ -92,19 +100,20 @@
         Write(Y,',');
         DoCheck;
     
    -    Y := QWord(X) div $8000000000000000;
    +    { Constants this large default to being made into Int64's, so typecast them }
    +    Y := QWord(X) div QWord($8000000000000000);
         Write(Y,',');
         DoCheck;
     
    -    Y := QWord(X) mod $8000000000000000;
    +    Y := QWord(X) mod QWord($8000000000000000);
         Write(Y,',');
         DoCheck;
     
    -    Y := QWord(X) div $8000000000000001;
    +    Y := QWord(X) div QWord($8000000000000001);
         Write(Y,',');
         DoCheck;
     
    -    Y := QWord(X) mod $8000000000000001;
    +    Y := QWord(X) mod QWord($8000000000000001);
         Writeln(Y);
         DoCheck;
       end;
    
    tmoddiv4.patch (3,430 bytes)

Activities

J. Gareth Moreton

2019-03-03 03:24

developer  

tmoddiv4.patch (3,430 bytes)
Index: tests/test/cg/tmoddiv4.pp
===================================================================
--- tests/test/cg/tmoddiv4.pp	(revision 41558)
+++ tests/test/cg/tmoddiv4.pp	(working copy)
@@ -3,6 +3,9 @@
 const
   TestValues: array[0..10] of QWord = (500, 1, 0, 995, $100000000, $100000001, $7FFFFFFFFFFFFFFF, QWord($8000000000000000), QWord($8000000000000001), QWord($8000000000000002), 1000000);
 
+  { Divisors are only for the error reporting }
+  Divisors: array[0..8] of QWord = (1000, 1, 3, $1000, $7FFFFFFF, $80000000, $7FFFFFFFFFFFFFFF, QWord($8000000000000000), QWord($8000000000000001));
+
 const
   ExpectedResults: array[0..10,1..18] of QWord = (
     (0,500,500,0,166,2,0,500,0,500,0,500,0,500,0,500,0,500),
@@ -11,10 +14,10 @@
     (0,995,995,0,331,2,0,995,0,995,0,995,0,995,0,995,0,995),
     (4294967,296,4294967296,0,1431655765,1,1048576,0,2,2,2,0,0,4294967296,0,4294967296,0,4294967296),
     (4294967,297,4294967297,0,1431655765,2,1048576,1,2,3,2,1,0,4294967297,0,4294967297,0,4294967297),
-    (9223372036854775,807,9223372036854775807,0,3074457345618258602,1,2251799813685247,4095,4294967298,1,4294967295,2147483647,1,0,0,9223372036854775807,18446744073709551615,0),
-    (9223372036854775,808,9223372036854775808,0,3074457345618258602,2,2251799813685248,0,4294967298,2,4294967296,0,1,1,1,0,1,18446744073709551615),
-    (9223372036854775,809,9223372036854775809,0,3074457345618258603,0,2251799813685248,1,4294967298,3,4294967296,1,1,2,0,9223372036854775809,1,0),
-    (9223372036854775,810,9223372036854775810,0,3074457345618258603,1,2251799813685248,2,4294967298,4,4294967296,2,1,3,0,9223372036854775810,0,9223372036854775810),
+    (9223372036854775,807,9223372036854775807,0,3074457345618258602,1,2251799813685247,4095,4294967298,1,4294967295,2147483647,1,0,0,$7FFFFFFFFFFFFFFF,0,$7FFFFFFFFFFFFFFF),
+    (9223372036854775,808,9223372036854775808,0,3074457345618258602,2,2251799813685248,0,4294967298,2,4294967296,0,1,1,1,0,0,QWord($8000000000000000)),
+    (9223372036854775,809,9223372036854775809,0,3074457345618258603,0,2251799813685248,1,4294967298,3,4294967296,1,1,2,1,1,1,0),
+    (9223372036854775,810,9223372036854775810,0,3074457345618258603,1,2251799813685248,2,4294967298,4,4294967296,2,1,3,1,2,1,1),
     (1000,0,1000000,0,333333,1,244,576,0,1000000,0,1000000,0,1000000,0,1000000,0,1000000));
 
 var
@@ -25,7 +28,12 @@
   begin
     if Y<>ExpectedResults[C,Col] then
       begin
-        writeln('Error at ',C,' ',Col);
+        Write(#10'Error at ', C, ',', Col, ' - ', TestValues[C]);
+        if (Col and $1) = 0 then
+          Write(' mod ')
+        else
+          Write(' div ');
+        WriteLn(Divisors[(Col - 1) shr 1], ' - expected ', ExpectedResults[C,Col], ' got ', Y);
         halt(1);
       end;
     Inc(Col);
@@ -92,19 +100,20 @@
     Write(Y,',');
     DoCheck;
 
-    Y := QWord(X) div $8000000000000000;
+    { Constants this large default to being made into Int64's, so typecast them }
+    Y := QWord(X) div QWord($8000000000000000);
     Write(Y,',');
     DoCheck;
 
-    Y := QWord(X) mod $8000000000000000;
+    Y := QWord(X) mod QWord($8000000000000000);
     Write(Y,',');
     DoCheck;
 
-    Y := QWord(X) div $8000000000000001;
+    Y := QWord(X) div QWord($8000000000000001);
     Write(Y,',');
     DoCheck;
 
-    Y := QWord(X) mod $8000000000000001;
+    Y := QWord(X) mod QWord($8000000000000001);
     Writeln(Y);
     DoCheck;
   end;
tmoddiv4.patch (3,430 bytes)

Thaddy de Koning

2019-03-03 11:07

reporter   ~0114593

I think that the signed stuff for 32 bit+ should be fixed and make it Delphi compatible once again. That's really horrible with two codebases.

Pierre Muller

2019-03-04 23:09

developer   ~0114649

Patch tested and committed, thanks!

Pierre

Issue History

Date Modified Username Field Change
2019-03-03 03:24 J. Gareth Moreton New Issue
2019-03-03 03:24 J. Gareth Moreton Status new => assigned
2019-03-03 03:24 J. Gareth Moreton Assigned To => Pierre Muller
2019-03-03 03:24 J. Gareth Moreton File Added: tmoddiv4.patch
2019-03-03 03:25 J. Gareth Moreton Priority normal => low
2019-03-03 03:25 J. Gareth Moreton Severity minor => trivial
2019-03-03 03:26 J. Gareth Moreton Tag Attached: patch
2019-03-03 03:26 J. Gareth Moreton Tag Attached: regression
2019-03-03 03:26 J. Gareth Moreton Tag Attached: test
2019-03-03 03:27 J. Gareth Moreton Tag Attached: range checks
2019-03-03 11:07 Thaddy de Koning Note Added: 0114593
2019-03-04 23:09 Pierre Muller Fixed in Revision => 41589
2019-03-04 23:09 Pierre Muller Note Added: 0114649
2019-03-04 23:09 Pierre Muller Status assigned => resolved
2019-03-04 23:09 Pierre Muller Fixed in Version => 3.3.1
2019-03-04 23:09 Pierre Muller Resolution open => fixed