Skip to content

Swift 6.0.x crash on win/arm64 Release build #77220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nil4 opened this issue Oct 25, 2024 · 3 comments
Open

Swift 6.0.x crash on win/arm64 Release build #77220

nil4 opened this issue Oct 25, 2024 · 3 comments
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

Comments

@nil4
Copy link

nil4 commented Oct 25, 2024

Description

A compiler crash (assertion failure) occurs with swift build --configuration release on Windows ARM64. This is reproducible with Swift 6.0 and 6.0.1. With both Swift versions, the same code compiles without issue in debug configuration, or release on x64.

Summary of observed results:

Swift version Architecture Configuration Result
6.0 arm64 release 💥 crash
6.0 arm64 debug ✅ works
6.0 x64 release ✅ works -- https://github.com/royalapplications/royalvnc/actions/runs/11513028067/job/32049003371#step:7:909
6.0.1 arm64 release 💥 crash
6.0.1 arm64 debug ✅ works
6.0.1 x64 release ✅ works -- https://github.com/royalapplications/royalvnc/actions/runs/11513740438/job/32051009618#step:7:910

Reproduction

Clone the repo and check out the relevant commit:

> git clone https://github.com/royalapplications/royalvnc.git
> cd royalvnc
> git reset aaca28ae04a93615489e3a6ab9f21b6f6bf51086 --hard

Run swift build and observe the debug build succeds:

> swift build
Building for debugging...
[<<< build output elided >>>]
Build complete! (73.07s)

Run swift build --configuration release and observe assertion failure and build crash:

> swift build --configuration release
Building for production...
error: compile command failed due to exception 3 (use -v to see invocation)
error: failed parsing the Swift compiler output: unexpected JSON message: {
  "exception" : 3,
  "kind" : "abnormal-exit",
  "name" : "compile",
  "output" : "Assertion failed: getAlign() && *getAlign() == Align && \"Alignment representation error!\", file C:\\Users\\swift-ci\\jenkins\\workspace\\swift-6.0.0-windows-toolchain-arm64\\llvm-project\\llvm\\lib\\IR\\Globals.cpp, line 140\r\nPlease submit a bug report (https:\/\/swift.org\/contributing\/#reporting-bugs) and include the crash backtrace.\r\nException Code: 0x80000003\r\nAssertion failed: getAlign() && *getAlign() == Align && \"Alignment representation error!\", file Rename failed: C:\\dev\\royalvnc\\.build\\aarch64-unknown-windows-msvc\\release\\RoyalVNCKit.build\\VNCRegion+CG.swift-fb46aa97.o.tmpC:\\Users\\swift-ci\\jenkins\\workspace\\swift-6.0.0-windows- -> toolchain-arm64\\llvm-project\\llvm\\lib\\IR\\Globals.cpp,C:\\dev\\royalvnc\\.build\\aarch64-unknown-windows-msvc\\release\\RoyalVNCKit.build\\VNCRegion+CG.swift.o line 140\r\n: permission denied\r\n",
  "pid" : 3180,
  "process" : {
    "real_pid" : 3180
  }
}: dataCorrupted(Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "kind", intValue: nil)], debugDescription: "invalid kind", underlyingError: nil))

Stack dump

> swift build --configuration release
Building for production...
error: compile command failed due to exception 3 (use -v to see invocation)
error: failed parsing the Swift compiler output: unexpected JSON message: {
  "exception" : 3,
  "kind" : "abnormal-exit",
  "name" : "compile",
  "output" : "Assertion failed: getAlign() && *getAlign() == Align && \"Alignment representation error!\", file C:\\Users\\swift-ci\\jenkins\\workspace\\swift-6.0.0-windows-toolchain-arm64\\llvm-project\\llvm\\lib\\IR\\Globals.cpp, line 140\r\nPlease submit a bug report (https:\/\/swift.org\/contributing\/#reporting-bugs) and include the crash backtrace.\r\nException Code: 0x80000003\r\nAssertion failed: getAlign() && *getAlign() == Align && \"Alignment representation error!\", file Rename failed: C:\\dev\\royalvnc\\.build\\aarch64-unknown-windows-msvc\\release\\RoyalVNCKit.build\\VNCRegion+CG.swift-fb46aa97.o.tmpC:\\Users\\swift-ci\\jenkins\\workspace\\swift-6.0.0-windows- -> toolchain-arm64\\llvm-project\\llvm\\lib\\IR\\Globals.cpp,C:\\dev\\royalvnc\\.build\\aarch64-unknown-windows-msvc\\release\\RoyalVNCKit.build\\VNCRegion+CG.swift.o line 140\r\n: permission denied\r\n",
  "pid" : 3180,
  "process" : {
    "real_pid" : 3180
  }
}: dataCorrupted(Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "kind", intValue: nil)], debugDescription: "invalid kind", underlyingError: nil))

Expected behavior

The assertion failure observed with arm64/release is unexpected. The build should work the same as arm64/debug locally, and x64/release on GitHub CI -- producing a compile error, or completing successfully.

Environment

> swiftc --version
Swift version 6.0.1 (swift-6.0.1-RELEASE)
Target: aarch64-unknown-windows-msvc

> ver
Microsoft Windows [Version 10.0.22621.4317]

Additional information

ref. royalapplications/royalvnc#11 (comment)

@nil4 nil4 added 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 labels Oct 25, 2024
@nil4
Copy link
Author

nil4 commented Oct 28, 2024

Repro steps updated and simplified -- involving only Swift tools.

@nil4
Copy link
Author

nil4 commented Oct 29, 2024

Tested swiftc 6.0.2 and the issue is still reproducible.

@hjyamauchi
Copy link
Contributor

I think this is caused by an MSVC arm64 miscompile issue that I reported here which was reported to MS and fixed here.

The upshot is that Visual Studio 17.9.x and 17.10.x (MSVC 14.39.x and 14.40.x, respecitively) compilers have an arm64 optimization bug and we need to use Visual Studio 17.8.x or earlier or 17.11.x or later to build the Windows/arm64 Swift toolchain to avoid this issue.

It appears that the swift.org CI is currently set up to use VS 17.9.x (MSVC 14.39.x). The latest release 6.0.3 still has the issue, unfortunately.

nil4 added a commit to royalapplications/royalvnc that referenced this issue Apr 15, 2025
nil4 added a commit to royalapplications/royalvnc that referenced this issue Apr 15, 2025
ref. https://github.blog/changelog/2025-04-14-windows-arm64-hosted-runners-now-available-in-public-preview/

* Remove `win-arm64` workaround for swiftlang/swift#77220
* Specify `arch` explicitly when installing Swift tooling; the default is `amd64` ref.
https://github.com/compnerd/gha-setup-swift/blob/17be5ca66ad69b44177f01b6b0b23575d3d7791a/action.yml#L22
* Set matching `arch` for both MSVC/WinSDK and Swift; contrary to docs, it defaults to `amd64` and not `arm64` (i.e. `host_arch`)
* Remove experimental `arm64` build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants