Log On
Embarcadero Home
Watch, Follow, &
Connect with Us
Share This
QualityCentral
Communities
Articles
Blogs
Resources
Downloads
Help
QualityCentral
Delphi-BCB
Compiler
Delphi
Anonymous Methods
BASM
Code Generation/Optimization
Error Recovery
Errors - Warnings
Exceptions
Execution
Finalization
Generics
Header Generation
Interaction with UI
Interfaces
Language
Linker
Make Logic
Memory Manager
OBJ Generation
OBJ Support
Other Compiler
Packages
RTTI
String Resources
TD Debug Info
Thread Local Storage
Version resilience
You are not logged in.
Help
Print
Public Report
Report From:
Delphi-BCB/Compiler/Delphi/Code Generation/Optimization
[ Add a report in this area ]
Report #:
102926
Status:
Closed
Compiler bug, apparently related to the optimiser
Project:
Delphi
Build #:
16.0.4358.45540
Version:
16.3
Submitted By:
David Heffernan
Report Type:
Crash / Data loss / Total failure
Date Reported:
1/26/2012 5:30:20 AM
Severity:
Serious / Highly visible problem
Last Updated:
9/5/2012 8:01:50 PM
Platform:
All versions
Internal Tracking #:
289659
Resolution:
Fixed
(Resolution Comments)
Resolved in Build:
:
17.0.4625.53395
Duplicate of:
None
Voting and Rating
Overall Rating:
No Ratings Yet
0.00 out of 5
Total Votes:
5
Description
The compiler has a rather nasty bug related to parameter passing that is very hard to reproduce. In order to do so I have had to copy the original code in my app and mock the various objects that are used by the mis-behaving routine.
The function in question, when optimisation is enabled, loses track of its self pointer and ends up passing garbage to another procedure.
The bug affects the 32 bit Windows compiler. It does not affect the 64 bit compiler.
Steps to Reproduce:
The attached program illustrates a compiler bug. The code gen is clearly incorrect. The code gen is fine when optimisation is switched off, but broken when optimisation is on. The bug is present in D6 and D2010 also. I did not test any other versions. The bug affects the 32 bit Windows compiler. It does not affect the 64 bit compiler.
The error occurs at this piece of code. The parameter passing is incorrect because the emitted code uses an incorrect Self pointer.
Origin3DSeabed := FSeabedOrigin;
if SpecialDouble(Origin3DSeabed.Z) then begin
Origin3DSeabed.Z := 0.0; // Ensure that something is drawn even if the depth at the origin is infinite.
end;
ViewPort.DrawGeneralSurface(
Origin3DSeabed,
FSeabedOrientation,
GridSize,
GridSize,
ViewPort.ScaleBarSize/5.0,
ViewPort.ScaleBarSize/5.0,
sdtGrid,
stGeneral,
FSeabedPenData,
[],
FSeabedPenData,
CalcSeabedZForRegularlySpacedLine
);
The (annotated) assembly for this is:
CompilerOptimisationBug.dpr.204: Origin3DSeabed := FSeabedOrigin;
0045DBBA 8B07 mov eax,[edi] // [edi] is Self
0045DBBC 8D7018 lea esi,[eax+$18]
0045DBBF 8D7DC0 lea edi,[ebp-$40]
0045DBC2 B906000000 mov ecx,$00000006
0045DBC7 F3A5 rep movsd //oops, this modifies edi
........
0045DC39 8B07 mov eax,[edi] //eax is meant to be Self, but is not due to edi having been modified by rep movsd
0045DC3B 8D4830 lea ecx,[eax+$30]
0045DC3E 8D55C0 lea edx,[ebp-$40]
0045DC41 8B4508 mov eax,[ebp+$08]
0045DC44 8B40FC mov eax,[eax-$04]
0045DC47 E82C020000 call TViewPort.DrawGeneralSurface
I would have added a more complete diagnosis but your QC software limits how much text I can enter! Please allow me to add more text!
Workarounds
None
Attachment
CompilerOptimisationBug.zip
Comments
None
View Your Reports
Search
Server Response from: ETNACODE01
Developer Tools
Blackfish SQL
C++Builder
Delphi
FireMonkey
Prism
InterBase
JBuilder
J Optimizer
HTML5 Builder
3rdRail & TurboRuby
Database Tools
Change Manager
DBArtisan
DB Optimizer
ER/Studio
Performance Center
Rapid SQL
Technical Articles
Tutorials
White Papers
Press Releases
Newsletters
Add Content (GetPublished)
Audio
Audio & Video
Video
Bugs & Suggestions (QualityCentral)
Discussion Forums
Examples (CodeCentral)
Tags
Technology Partners
Downloads
Free Trials
Registered User Downloads
Beta Programs
Add Content (GetPublished)
Articles
Blogs
Bugs & Suggestions (QualityCentral)
Discussion Forums
Examples (CodeCentral)
Member Services
About
Connect with Us