-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Open
Labels
SILbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Description
Description
assertionFailure() crashes when compiled with -Onone -assert-config Release. In contrast, assert() correctly respects -assert-config Release at all optimization levels.
Reproduction
// test.swift
assertionFailure("Should not crash")
print("SURVIVED")# Crashes (unexpected)
$ swiftc test.swift -Onone -assert-config Release -o test && ./test
Fatal error: Should not crash
# Works correctly
$ swiftc test.swift -O -assert-config Release -o test && ./test
SURVIVEDCompare with assert():
// test_assert.swift
assert(false, "Should not crash")
print("SURVIVED")# Works correctly at -Onone
$ swiftc test_assert.swift -Onone -assert-config Release -o test && ./test
SURVIVED
# Works correctly at -O
$ swiftc test_assert.swift -O -assert-config Release -o test && ./test
SURVIVEDExpected behavior
Both assert() and assertionFailure() are debug-only assertions. When compiled with -assert-config Release, both should be disabled regardless of optimization level. The -assert-config flag should control assertion behavior consistently across all assertion types.
Environment
Apple Swift version 6.2 (swiftlang-6.2.0.19.9 clang-1700.3.19.1)
Target: arm64-apple-macosx15.0
Additional information
Looking at Assert.swift, the two functions use different attributes:
assert() uses @_transparent:
- Appears to inline at SIL level into user code
- Seems to evaluate
_isDebugAssertConfiguration()with user's compilation flags - Works as expected at
-Onone
assertionFailure() uses @inlinable + @inline(__always):
- At
-Onone, the generated assembly shows a function call rather than inlined code - Might be calling into pre-compiled stdlib where
_isDebugAssertConfiguration()was evaluated differently - This could explain why it doesn't respect the user's
-assert-config Releaseflag
Metadata
Metadata
Assignees
Labels
SILbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.