[AVR] swift frontend crashes when trying to emit LLVM IR #78380
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
crash
Bug: A crash, i.e., an abnormal termination of software
triage needed
This issue needs more specific labels
Description
In attempting to move to a working swift compiler, able to produce AVR object files there are a number of obstacles. While the basic front end functions now support AVR and the standard library has been upgraded to support 16-bit platforms, a pre-requisite for Swift on AVR... we still have not managed to produce AVR object files.
There appear to be some (separate) issues with the LLVM back end for AVR being used in the current Swift trunk, which I will investigate separately after we have Swift reliably producing bitcode/llvm-IR on the AVR platform. Hopefully that will just resolve as more recent AVR bugfixes make their way through into the Swift llvm-project branches. We can re-assess later.
Until IRGen works for AVR, we will definitely never be able to produce object files for AVR.
At the moment, even the most basic files trap in IRGen, due to issues with invalid casts. The root cause is the Swift front end not respecting the LLVM program address space in the AVR back end data layout. On the AVR platform, regular RAM pointers live in address space 0 but function/program pointers all live in address space 1, which physically corresponds to flash memory instead of RAM on the AVR microcontroller chips... due to the limitations of 16-bit pointer addressing, flash memory and RAM cannot be separated just by address location, as they are on ARM Cortex M0 platforms for example. So I believe the proper fix for the Swift front end is to respect LLVM data layout program address space in various places.
Modifying it everywhere would be a large job and is probably not necessary, for example most metadata emission does not apply to embedded Swift.
Reproduction
// RUN: %swift-frontend -emit-ir %s -target avr-none-none-elf \ // RUN: -wmo -enable-experimental-feature Embedded import Swift
If the above file is saved as test.swift and attempted compile to IR with...
swift-frontend -emit-ir -target avr-none-none-elf -enable-experimental-feature Embedded -wmo test.swift
...the assertion is immediately seen.
Assertion failed: (castIsValid(op, S, Ty) && "Invalid cast!"), function Create, file Instructions.cpp, line 2974
Stack dump
Expected behavior
This file should compile to trivial IR with an empty main method body.
Environment
Swift version 6.2-dev (LLVM 9f6c3d784782c34, Swift 55189ba)
Additional information
Initially reported here:
https://forums.swift.org/t/avr-irgen-traps-on-lowering-invalid-cast-assertion-thrown-by-llvm/76883
The text was updated successfully, but these errors were encountered: