IDE: Access violation upon startup when built with "-O3" [CRASH] [Regression]

Lazarus version: 4.99, start at freepascal.org/lazarus/lazarus@b7f3704f
FPC version: 3.2.2
OS: Windows 8 x64
CPU 64 bits, IDE 32 bits (others not tested)

Summary

If the IDE is built with the "Optimized IDE" profile, an "Access violation" occurs upon startup. The same issue occurs with the debug profile if add the -O3 option.

If click "OK" ("to ignore and risk ...") in the error message, the editor will remain blank:

Error Expected
image image

This also reproduces with a clean configuration.

Bisection result

The guilty commit is freepascal.org/lazarus/lazarus@b7f3704f. @martin_frb, please take a look.

Stack trace

Click to expand
#0 TLazEditTextAttributeMergeResult.Merge(TLazEditTextAttributeMergeResult($109BF100), TLazCustomEditTextAttribute($109BF100)) at lazedittextattributes.pas:1389
#1 TSynEditMarkup.MergeMarkupAttributeAtRowCol(TSynEditMarkup($00000001), Failed to read data from register, Failed to read data from register (while calculating location), Failed to read data from register (while calculating location), Failed to read data from register (while calculating location), TLazEditTextAttributeMergeResult($00000001)) at syneditmarkup.pp:484
#2 TSynEditMarkupManager.MergeMarkupAttributeAtRowCol(Failed to read data from register, Failed to read data from register, Failed to read data from register (while calculating location), Failed to read data from register (while calculating location), Failed to read data from register (while calculating location), Failed to read data from register) at syneditmarkup.pp:656
#3 TLazSynPaintTokenBreaker.GetNextHighlighterTokenEx(Failed to read data from register, Failed to read data from register (while calculating location)) at lazsyntextarea.pp:508
#4 PaintLines($parentfp_void_pointer($109BF4F0)) at lazsyntextarea.pp:1978
#5 TLazSynTextArea.PaintTextLines(TLazSynTextArea($1563CC50), TRect (19; 0; 380; 420; TPoint (19; 0); TPoint (380; 420); (19, 0, 380, 420)), 0, 26, 1, 62) at lazsyntextarea.pp:2048
#6 TLazSynTextArea.DoPaint(Failed to read data from register, Failed to read data from register, TRect (19; 0; 380; 420; TPoint (19; 0); TPoint (380; 420); (19, 0, 380, 420))) at lazsyntextarea.pp:1657
#7 TLazSynSurface.Paint(Failed to read data from register, Failed to read data from register, TRect (17; 0; 380; 420; TPoint (17; 0); TPoint (380; 420); (17, 0, 380, 420))) at syneditmiscclasses.pp:1101
#8 TLazSynSurfaceManager.DoPaint(Failed to read data from register, Failed to read data from register, TRect (0; 0; 393; 420; TPoint (0; 0); TPoint (393; 420); (0, 0, 393, 420))) at lazsyntextarea.pp:1293
#9 TLazSynSurface.Paint(TLazSynSurface($1563BDB0), Failed to read data from register, TRect (0; 0; 393; 420; TPoint (0; 0); TPoint (393; 420); (0, 0, 393, 420))) at syneditmiscclasses.pp:1101
#10 TSourceLazSynSurfaceManager.DoPaint(Failed to read data from register, Failed to read data from register, TRect (0; 0; 393; 420; TPoint (0; 0); TPoint (393; 420); (0, 0, 393, 420))) at sourcesyneditor.pas:1500
#11 TLazSynSurface.Paint(TLazSynSurface($1563BDB0), Failed to read data from register, TRect (0; 0; 393; 420; TPoint (0; 0); TPoint (393; 420); (0, 0, 393, 420))) at syneditmiscclasses.pp:1101
#12 TCustomSynEdit.Paint(TCustomSynEdit($17D65ED0)) at synedit.pp:4549
#13 TCustomControl.PaintWindow(TCustomControl($17D65ED0), 4244710750) at customcontrol.inc:123
#14 TWinControl.PaintHandler(TWinControl($17D65ED0), TLMPaint (15; 4244710750; $109BF8FC; 0)) at wincontrol.inc:4982
#15 TWinControl.WMPaint(TWinControl($17D65ED0), TLMPaint (15; 4244710750; $109BF8FC; 0)) at wincontrol.inc:6943
#16 TCustomControl.WMPaint(Failed to read data from register, Failed to read data from register (while calculating location)) at customcontrol.inc:103
#17 SYSTEM$_$TOBJECT_$__$$_DISPATCH$formal+145 at :0
#18 TControl.WndProc(TControl($17D65ED0), TMessage (15; -50256546; 278657276; 0; 9566; 64769; TDWordFiller (); 63740; 4251; TDWordFiller (); 0; 0; TDWordFiller ())) at control.inc:2299
#19 TWinControl.WndProc(Failed to read data from register, Failed to read data from register (while calculating location)) at wincontrol.inc:5547
#20 TCustomSynEdit.WndProc(Failed to read data from register, Failed to read data from register (while calculating location)) at synedit.pp:6910
#21 DeliverMessage(TObject($17D65ED0), Unknown type($109BFB88)) at lclmessageglue.pas:114
#22 TWINDOWPROCHELPER.SendPaintMessage(TWindowProcHelper (5641612; 15; 0; 0; TMessage (0; 0; 0; 0; 0; 0; TDWordFiller (); 0; 0; TDWordFiller (); 0; 0; TDWordFiller ()); $109BFB50; TWinControl($17D65ED0); False; False; $14A35BE8; TDoubleBuffer (0; 0; 0; 0); 414; 424; TLMPaint (15; 4244710750; $109BF8FC; 0); False; 0; TLMScroll (0; 0; 0; 0; 0; 0); TLMKey (0; 0; 0; 0; 0); TLMKey (0; 0; 0; 0; 0); TLMMouse (0; 0; 0; 0; TSmallPoint (0; 0); 0; 0); TLMContextMenu (0; 0; 0; 0; TSmallPoint (0; 0); 0; 0); TLMMouse (0; 0; 0; 0; TSmallPoint (0; 0); 0; 0); TLMMouseEvent (0; 0; 0; 0; 0; 0; nil; []); TLMMove (0; 0; 0; 0; TSmallPoint (0; 0); 0; 0); TLMNotify (0; 0; nil; 0); TDrawListItemStruct (0; TRect (0; 0; 0; 0; TPoint (0; 0); TPoint (0; 0); TArray4IntegerType({4 elements})); 0; []); nil; TWinControl($17D65ED0)), 0) at win32callback.inc:759
#23 TWINDOWPROCHELPER.DoWindowProc(TWindowProcHelper (5641612; 15; 0; 0; TMessage (0; 0; 0; 0; 0; 0; TDWordFiller (); 0; 0; TDWordFiller (); 0; 0; TDWordFiller ()); $109BFB50; TWinControl($17D65ED0); False; False; $14A35BE8; TDoubleBuffer (0; 0; 0; 0); 414; 424; TLMPaint (15; 4244710750; $109BF8FC; 0); False; 0; TLMScroll (0; 0; 0; 0; 0; 0); TLMKey (0; 0; 0; 0; 0); TLMKey (0; 0; 0; 0; 0); TLMMouse (0; 0; 0; 0; TSmallPoint (0; 0); 0; 0); TLMContextMenu (0; 0; 0; 0; TSmallPoint (0; 0); 0; 0); TLMMouse (0; 0; 0; 0; TSmallPoint (0; 0); 0; 0); TLMMouseEvent (0; 0; 0; 0; 0; 0; nil; []); TLMMove (0; 0; 0; 0; TSmallPoint (0; 0); 0; 0); TLMNotify (0; 0; nil; 0); TDrawListItemStruct (0; TRect (0; 0; 0; 0; TPoint (0; 0); TPoint (0; 0); TArray4IntegerType({4 elements})); 0; []); nil; TWinControl($17D65ED0))) at win32callback.inc:2387
#24 WindowProc(Failed to read data from register, Failed to read data from register, Failed to read data from register, Failed to read data from register) at win32callback.inc:2822
#25 user32:CallNextHookEx+177 at :0
#26 user32:GetAncestor+461 at :0
#27 user32:CallNextHookEx+1388 at :0
#28 user32:CallNextHookEx+1897 at :0
#29 ntdll:KiUserCallbackDispatcher+54 at :0
#30 user32:DispatchMessageW+16 at :0
#31 TWin32WidgetSet.AppProcessMessages(TWin32WidgetSet($00375EB8)) at win32object.inc:422
#32 TApplication.HandleMessage(TApplication($0030DCF0)) at application.inc:1326
#33 TApplication.RunLoop(TApplication($0030DCF0)) at application.inc:1469
#34 TWidgetSet.AppRun(Failed to read data from register, Failed to read data from register (while calculating location)) at interfacebase.inc:54
#35 TApplication.Run(Failed to read data from register) at application.inc:1457
#36 $main at lazarus.pp:159
#37 SYSTEM_$$_EXE_ENTRY$TENTRYINFORMATION+71 at :0
#38 SYSINITPAS_$$__FPC_WINMAINCRTSTARTUP+42 at :0
#39 KERNEL32:BaseThreadInitThunk+36 at :0
#40 ntdll:RtlInitializeExceptionChain+143 at :0
#41 ntdll:RtlInitializeExceptionChain+90 at :0

The "Failed to read data from register" messages are likely due to the -O3 option.

Edited by n7800