[fpc-devel] Optimization breaks check for overridden function / Is there a better way to check?
Pierre Muller
pierre at freepascal.org
Fri Oct 17 19:54:52 CEST 2025
Hi David,
this looks very similar to a problem that we are trying to
debug for a while, and that I recently submitted as a bug report:
https://gitlab.com/freepascal.org/fpc/source/-/issues/41439
The problem has been nicely simplified by alligator in
https://gitlab.com/freepascal.org/fpc/source/-/issues/41444
There is some problem related to PPU writing...
I hope to be able using this simplified example t understand better this issue,
but I am currently still busy with the previous issue, also raised by alligator:
https://gitlab.com/freepascal.org/fpc/source/-/issues/41443
for which I hope to have found a fix.
Pierre
Le 17/10/2025 à 19:35, David Jenkins via fpc-devel a écrit :
> What is the best way to check if a virtual function in a base class has
> been overridden by a class that inherits the base class?
>
> In LCL TPrinter.pas the following check is used:
>
>
> procedure TPrinter.NewPage;
> begin
> Inc(fPageNumber);
> if TMethod(@Self.DoNewPage).Code = Pointer(@TPrinter.DoNewPage) then
> begin
> ..
> end
> ..
> end
>
> We have run across an optimization problem with the TCocoaPrinter class
> and that TPrinter code.
>
> TCocoaPrinter = class(TPrinter)
>
> with no override of DeNewPage
>
> Sometime with Level2 or Level3 optimization,
> TMethod(@Self.DoNewPage).Code is changed to point to systemh.inc
> EmptyMethod instead of TPrinter.DoNewPage and the check no longer works
> appropriately.
>
> Is there another way to make that check that is not affected by
> optimization?
>
> I will eventually throw a fix to the LCL folks but we use a similar
> formulation in our code and are concerned that it might also be affected
> by optimization at some point. Right now it is not because none of the
> base functions are completely empty, but they are trivial functions that
> match each other and could be optimized in the future by coalescing them.
>
> Thanks
> David Jenkins
> Scooter Software.
>
>
> _______________________________________________
> fpc-devel maillist - fpc-devel at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
More information about the fpc-devel
mailing list