Hello Swift community,
I know that you should never blame the compiler for your own code, but...
With one of my small test programs I have a snippet which works correctly in Debug Builds but not in Release Builds.
if end != start {
let startMinusOne = start.advanced(by: -1)
startMinusOne.pointee = start.pointee
//print(startMinusOne.pointee) included in last version
start.pointee = 0x2E
start = startMinusOne
}
Both start and end are UnsafeMutablePointer.
This code produces the following assembler code (ARM64):
-> 0x100003160 <+284>: cmp x22, x9 ; x22 = end, x9 = start
0x100003164 <+288>: b.eq 0x100003174 ; <+304> at Decimal64.swift
0x100003168 <+292>: mov w8, #0x2e ; =46
0x10000316c <+296>: strb w8, [x9], #-0x1
0x100003170 <+300>: mov x23, x9
The Swift code line "startMinusOne.pointee = start.pointee" is clearly missing in this assembler code. If I comment this line out, I get the exact same assembler code. The Debug Build assembler is much longer, but produces a correct result.
Is this a bug in the optimizer or am I doing something wrong?
Kind regards,
Dirk