Skip to content

Commit 3f470b0

Browse files
author
Harlan
authored
[stdlib] Break infinite recursion false positive in _fatalErrorMessage (#19693)
Introduce an inner function that breaks the infinite recursion check, silencing this warning: ``` swift/stdlib/public/core/AssertCommon.swift:166:15: warning: all paths through this function will call itself internal func _fatalErrorMessage( ^ ```
1 parent 3ea7544 commit 3f470b0

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

stdlib/public/core/AssertCommon.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,21 @@ internal func _fatalErrorMessage(
167167
file: StaticString, line: UInt,
168168
flags: UInt32
169169
) -> Never {
170+
// This function breaks the infinite recursion detection pass by introducing
171+
// an edge the pass doesn't look through.
172+
func _withUTF8Buffer<R>(
173+
_ string: StaticString,
174+
_ body: (UnsafeBufferPointer<UInt8>) -> R
175+
) -> R {
176+
return string.withUTF8Buffer(body)
177+
}
178+
170179
#if INTERNAL_CHECKS_ENABLED
171-
prefix.withUTF8Buffer {
180+
_withUTF8Buffer(prefix) {
172181
(prefix) in
173-
message.withUTF8Buffer {
182+
_withUTF8Buffer(message) {
174183
(message) in
175-
file.withUTF8Buffer {
184+
_withUTF8Buffer(file) {
176185
(file) in
177186
_swift_stdlib_reportFatalErrorInFile(
178187
prefix.baseAddress!, CInt(prefix.count),
@@ -183,9 +192,9 @@ internal func _fatalErrorMessage(
183192
}
184193
}
185194
#else
186-
prefix.withUTF8Buffer {
195+
_withUTF8Buffer(prefix) {
187196
(prefix) in
188-
message.withUTF8Buffer {
197+
_withUTF8Buffer(message) {
189198
(message) in
190199
_swift_stdlib_reportFatalError(
191200
prefix.baseAddress!, CInt(prefix.count),

0 commit comments

Comments
 (0)