Aggressive optimization causes app to crash

As the subject line says:

  • runs fine under debugger regardless of optimization level
  • built app runs fine with default or moderate optimization
  • built app crashes with aggressive optimization

The crash log shows:
Crashed Thread: 0 Dispatch queue:

Exception Codes: KERN_INVALID_ADDRESS at 0x0000000100000000

Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [0]

VM Regions Near 0x100000000:

__TEXT 000000010b479000-000000010b5d3000 [ 1384K] r-x/r-x SM=COW /Volumes/VOLUME/*/

Application Specific Information:
Performing @selector(performClick:) from sender XOJButton 0x60800014c290

Thread 0 Crashed:: Dispatch queue:
0 com.pkstys.aggressiveoptimizationtest 0x000000010b5bb5ea zlibModule.zlibUncompressMB%i8%ou4ou4 + 74
1 com.pkstys.aggressiveoptimizationtest 0x000000010b5b4ff8 Window1.Window1.PushButton1_Action%%o<Window1.Window1>o + 1032

Initially I thought it was the zlib decompressor that was crashing but zlibUncompressMB is just a wrapper to a newer decompressor method that actually does the decompression. It’s the simple wrapper method that crashes (if I call the real decompressor directly all is good).

You can see what I mean with this very simple project:

This is very worrisome if you can’t know which seemingly trivial parts of your code will or will not run correctly depending on compiler optimization level.

macOS, xojo 2021r2.1

Please make a feedback case.
I think it’s this line in assembler:

cmp qword [rbx], 0x0

and rbx is set before to

mov rbx, qword [_gCurrentException_1001bdf18]

and between that is the function call, which overwrites rbx register.
So the xojo compiler doesn’t tell LLVM to preserve register or to assume after function call, that it is overwritten.

1 Like


Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.