Skip to content

Top Level lets causing EXC_BAD_ACCESS #62974

Open
@alexito4

Description

@alexito4

Description
I have a reproducible case of top level let declarations randomly causing crashes.
The project is a simple Swift CLI tool, using https://github.com/pointfreeco/swift-parsing .
You can find the specific branch with the problem here https://github.com/alexito4/kindle-highlights/tree/swift-crash-repo and a conversation on the swift-parsing repo pointfreeco/swift-parsing#275
I've discarded pretty much anything else I could, there is another branch trying-fixes where I removed everything I could and still crashes, albeit at different points (which to me points to some memory issue since every slight change in the program makes it crash differently)

Steps to reproduce

  1. Checkout https://github.com/alexito4/kindle-highlights.git
  2. Switch to the swift-crash-repo branch
  3. Run swift run -c release kindle-highlights ./short.txt and see it crash with 6993 bus error
  4. Run (in debug) swift run kindle-highlights ./short.txt and it works fine (at least on my machine) ✅
  5. You can also open Xcode xed . and run the tests, you will get a Thread 1: EXC_BAD_ACCESS ❌ Note that some tests also fail (before crashing) due to what seems some bad memory when manipulating the strings.

Expected behavior
It shouldn't crash.

Screenshots
Crash running tests trough Xcode:
Screenshot 2023-01-11 at 19 53 53

Crash running with release config:
Screenshot 2023-01-11 at 19 54 28

Environment

  • Swift compiler version info: swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51) Target: arm64-apple-macosx13.0
  • Xcode version info: Version 14.2 (14C18)
  • Deployment target: macOS 13.1 (22C65)

I've also tried running it in Docker with the same results. Docker Image swift-5.7.2 platform ubuntu22.04

Additional context
After being pointed to an issue with top level declarations pointfreeco/swift-parsing#275 (comment) I switched the code to use functions and create the parsers instead of storing them in top level lets and all the problems have gone away. (the diff is here alexito4/kindle-highlights@c82ce47)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwareglobal let & varFeature: global constants and variablesmemory corruptionrun-time crashBug → crash: Swift code crashed during executionswift 5.7

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions