I’m having a spot of bother with this code…
var staticArray: InlineArray<3,UInt8> = [3,11,29]
var i = 0
var previous: UInt8 = 0
while(true) {
if staticArray[i] == 29 {
staticArray[i] = previous
previous = previous &+ 2
}
previous = staticArray[i]
i = i &+ 1
i %= 2
}
…I’m compiling this with my own standard library (which is quite possibly the source of the issue) on the AVR platform with the command…
"/Users/carl/Desktop/S4A IDE Pro (beta).app/Contents/XPCServices/BuildEngine.xpc/Contents/MacOS/swiftc" -emit-ir -O -nostdimport -enforce-exclusivity=unchecked -no-link-objc-runtime -Xfrontend -disable-reflection-metadata -Xfrontend -disable-stack-protector -Xfrontend -disable-implicit-concurrency-module-import -Xfrontend -disable-implicit-string-processing-module-import -enable-experimental-feature Embedded -enable-experimental-feature SymbolLinkageMarkers -target avr-none-none-elf -whole-module-optimization -I "/Users/carl/Desktop/S4A IDE Pro (beta).app/Contents/XPCServices/BuildEngine.xpc/Contents/Resources/uSwift-AVR/Embedded" -I "/Users/carl/Desktop/S4A IDE Pro (beta).app/Contents/XPCServices/BuildEngine.xpc/Contents/Resources/uSwiftShims" -output-file-map build/outputMap.json -I "/Users/carl/Desktop/S4A IDE Pro (beta).app/Contents/XPCServices/BuildEngine.xpc/Contents/Resources/lib/avr-libc/include" -I "/Users/carl/Desktop/S4A IDE Pro (beta).app/Contents/XPCServices/BuildEngine.xpc/Contents/Resources/lib/avr-libgcc/include" -Xcc -DAVR_LIBC_DEFINED -Xcc -DLIBC_DEFINED -Xcc -D__AVR_ATmega328P__ -DAVR_LIBC_DEFINED_SWIFT -Xcc -DF_CPU=16000000 -Xcc -mmcu=atmega328p -I "/Users/carl/Library/Application Support/SwiftForArduino/Extensions/Modules/Embedded" -I "/Users/carl/Library/Application Support/SwiftForArduino/S4A/422/Modules/Embedded" -I /Users/carl/Documents/SwiftForArduino/Exports -module-name main main.swift -o /Users/carl/Documents/SwiftForArduino/6.2/build/main.ll
The compiler traps in what looks like the lib/SIL/Verifier/MemoryLifetimeVerifier.cpp …
warning: Unable to locate libSwiftScan. Fallback to `swift-frontend` dependency scanner invocation.
SIL memory lifetime failure in @main: memory is not initialized, but should be
memory location: %53 = alloc_stack $InlineArray<3, UInt8> // users: %60, %57, %56, %54
at instruction: %60 = mark_dependence [unresolved] %59 : $*UInt8 on %53 : $*InlineArray<3, UInt8> // user: %61
Abort: function reportError at MemoryLifetimeVerifier.cpp:265
in function:
// main
// Isolation: unspecified
sil [ossa] @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>):
alloc_global @$e4main11staticArrays06InlineC0Vy$2_s5UInt8VGvp // id: %2
Note, if I change var staticArray: InlineArray<3,UInt8> = [3,11,29] to let staticArray: InlineArray<3,UInt8> = [3,11,29] it compiles fine, but of course I can’t then change the contents of the inline array.
Also, I tried -emit-sil and even -emit-silgen but the compiler still seems to trap, so I’m guessing this pass runs before even raw SIL is emitted?
The compiler is forked from faad7c76585008cb7a5d0576fabc09a97c8c2c21 and is a modern compiler build (swift driver, swift-syntax, etc.)
I’m looking for advice how to track this down a bit, or anything obvious from a glance looking at the swift code. (The InlineArray in my stdlib is very little changed from normal.)
Thanks for any help and advice anyone can give!
Regards,
Carl