swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.7k stars 1.33k forks source link

[SR-13481] SwiftPM: Assertion behaviour inconsistent between swift and C/C++ #4504

Open benlangmuir opened 4 years ago

benlangmuir commented 4 years ago
Previous ID SR-13481
Radar rdar://problem/68159829
Original Reporter @benlangmuir
Type Bug

Attachment: Download

Environment Swift 5.3, Xcode 12
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Package Manager | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 88f80158fc8eac071055b74bfae5d006

Issue Description:

Building a package with --configuration release disables assertions in Swift code, but not in C/C++/ObjC.

The behaviour should be consistent across languages, and we should introduce a separate command-line option to explicitly control assertions for both swift and clang in release builds, since it is often useful to test in release+asserts.

$ swift test -c release
...
Assertion failed: (0 && "c assert"), function cFunc, file /private/tmp/asserts/Sources/casserts/casserts.c, line 5.
Exited with signal code 6

While in debug, assertions are enabled for both

$ swift test
...
Fatal error: swift assert: file asserts/asserts.swift, line 2
Exited with signal code 4
...
Assertion failed: (0 && "c assert"), function cFunc, file /private/tmp/asserts/Sources/casserts/casserts.c, line 5.
Exited with signal code 6
benlangmuir commented 4 years ago

Workaround to disable assertions in release builds:

cSettings: [
    .define("NDEBUG", to: "1", .when(configuration: .release))
]),
typesanitizer commented 4 years ago

@swift-ci create

benlangmuir commented 2 years ago

Reproduces in 5.6