Skip to content

assertionFailure() Not Removed at -Onone -assert-config Release #85382

@zienag

Description

@zienag

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
SURVIVED

Compare 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
SURVIVED

Expected 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 Release flag

Metadata

Metadata

Assignees

No one assigned

    Labels

    SILbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions