View Issue Details

IDProjectCategoryView StatusLast Update
0036251FPCRTLpublic2019-11-03 15:42
ReporterThaddy de KoningAssigned ToFlorian 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformarmhfOSraspbian OS Versionbuster
Product Version3.3.1Product Build 
Target VersionFixed in Version3.3.1 
Summary0036251: still overload missing for min/max after 33161 is closed
DescriptionThe overloads for min/max for cardinal are commented out, but that causes Lazarus trunk to fail in multiple places.

If the cause of the trouble is in the function's body, they maybe can be rewritten like so:

function min(a,b:dword):dword;
begin
  result := a;
 if a > b then result := b;
end;

function max(a,b:dword):dword;
begin
  result := b;
  if a > b then result := a;
end;
Steps To ReproduceBuild lazarus trunk: fails.
Additional InformationAfter I added the above solution, lazarus builds again.
The body will generate distinctly different assembler with my solution.

If the cause of the potential trouble is otherwise, I have no problem fixing it at the lazarus side, but plz document why it causes trouble and what kind of trouble.
TagsNo tags attached.
Fixed in Revision43382
FPCOldBugId
FPCTarget-
Attached Files
  • 36251_htypechk.pas.patch (1,360 bytes)
    Index: compiler/htypechk.pas
    ===================================================================
    --- compiler/htypechk.pas	(revision 43374)
    +++ compiler/htypechk.pas	(working copy)
    @@ -3484,6 +3484,7 @@
             hp            : pcandidate;
             cntpd,
             res           : integer;
    +        lastpd       : tabstractprocdef;
           begin
             {
               Returns the number of candidates left and the
    @@ -3492,6 +3493,7 @@
             { Setup the first procdef as best, only count it as a result
               when it is valid }
             bestpd:=FCandidateProcs^.data;
    +        lastpd:=nil;
             if FCandidateProcs^.invalid then
              cntpd:=0
             else
    @@ -3528,12 +3530,20 @@
                    begin
                      { res=0, both are valid }
                      if not hp^.invalid then
    +                  begin
                        inc(cntpd);
    +                   lastpd:=besthpstart^.data;
    +                  end;
                    end;
                   hp:=hp^.next;
                 end;
              end;
     
    +        if cntpd>1 then
    +         begin
    +          bestpd:=lastpd;
    +          cntpd:=1;
    +         end;
             { if we've found one, check the procdefs ignored for overload choosing
               to see whether they contain one from a child class with the same
               parameters (so the overload choosing was not influenced by their
    
    36251_htypechk.pas.patch (1,360 bytes)

Relationships

related to 0036161 resolvedFlorian regression: Math.Min and sizeof cause "Error: Can't determine which overloaded function to call" 

Activities

Thaddy de Koning

2019-11-03 10:16

reporter   ~0119002

Last edited: 2019-11-03 10:16

View 2 revisions

after 36161 was closed. Typo.

Thaddy de Koning

2019-11-03 11:03

reporter   ~0119003

There are two other ones missing min/max(a:integer;b:dword)
Here I can see why this would cause trouble, but still it is needed because of:
var b:dword
result := min(0,b);

The zero is an integer literal and would need a cast by the user to solve.
Furthermore I see that is this case the result type is probematic.

The latter caused a break in laz.virtualtrees around line 13600.

Do-wan Kim

2019-11-03 12:36

reporter   ~0119007

I make patch last match overload proc for best overload proc. I don't know about side effect.

36251_htypechk.pas.patch (1,360 bytes)
Index: compiler/htypechk.pas
===================================================================
--- compiler/htypechk.pas	(revision 43374)
+++ compiler/htypechk.pas	(working copy)
@@ -3484,6 +3484,7 @@
         hp            : pcandidate;
         cntpd,
         res           : integer;
+        lastpd       : tabstractprocdef;
       begin
         {
           Returns the number of candidates left and the
@@ -3492,6 +3493,7 @@
         { Setup the first procdef as best, only count it as a result
           when it is valid }
         bestpd:=FCandidateProcs^.data;
+        lastpd:=nil;
         if FCandidateProcs^.invalid then
          cntpd:=0
         else
@@ -3528,12 +3530,20 @@
                begin
                  { res=0, both are valid }
                  if not hp^.invalid then
+                  begin
                    inc(cntpd);
+                   lastpd:=besthpstart^.data;
+                  end;
                end;
               hp:=hp^.next;
             end;
          end;
 
+        if cntpd>1 then
+         begin
+          bestpd:=lastpd;
+          cntpd:=1;
+         end;
         { if we've found one, check the procdefs ignored for overload choosing
           to see whether they contain one from a child class with the same
           parameters (so the overload choosing was not influenced by their
36251_htypechk.pas.patch (1,360 bytes)

C Western

2019-11-03 12:58

reporter   ~0119010

This affects (at least) 64 bit linux also

See also https://bugs.freepascal.org/view.php?id=33939

Florian

2019-11-03 15:41

administrator   ~0119012

@Do-win Kim selecting a random overload is no solution.

I will revert r43366 and add a comment to the wiki as proposed by Martin.

Issue History

Date Modified Username Field Change
2019-11-03 10:15 Thaddy de Koning New Issue
2019-11-03 10:16 Thaddy de Koning Note Added: 0119002
2019-11-03 10:16 Thaddy de Koning Note Edited: 0119002 View Revisions
2019-11-03 11:03 Thaddy de Koning Note Added: 0119003
2019-11-03 12:36 Do-wan Kim File Added: 36251_htypechk.pas.patch
2019-11-03 12:36 Do-wan Kim Note Added: 0119007
2019-11-03 12:58 C Western Note Added: 0119010
2019-11-03 15:40 Florian Relationship added duplicate of 0036161
2019-11-03 15:41 Florian Note Added: 0119012
2019-11-03 15:42 Florian Assigned To => Florian
2019-11-03 15:42 Florian Status new => resolved
2019-11-03 15:42 Florian Resolution open => duplicate
2019-11-03 15:42 Florian Fixed in Version => 3.3.1
2019-11-03 15:42 Florian Fixed in Revision => 43382
2019-11-03 15:42 Florian FPCTarget => -
2019-11-03 15:42 Florian Resolution duplicate => fixed
2019-11-03 15:42 Florian Relationship replaced related to 0036161