You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
kyulee-com opened this issue
May 27, 2024
· 4 comments
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwareSILGenArea → compiler: The SIL generation stage
We experienced a runtime crash attributed to a hoisted load for utf8ToString in the SwiftProtobuf library. Initially suspecting a loop optimizer issue, I reported it here: LLVM Project Issue #93110. Based on the feedback, it seems that $ss7UnicodeO4UTF8O13ForwardParserVs10_UTFParserssAGP7_buffers11_UIntBufferVy8Encoding_8CodeUnitQZGvMTW returns a nocapture pointer. This is demangled as protocol witness for Swift._UTFParser._buffer.modify : Swift._UIntBuffer<A.Encoding.CodeUnit> in conformance Swift.Unicode.UTF8.ForwardParser : Swift._UTFParser in Swift.
The relevant code can be found in the Swift repository: UTF8.swift Code.
Reproduction
To isolate the issue, I used the following simplified code snippet and generated similar problematic code:
The nocapture attribute on the passed argument %1 seems to be violated as it is saved to a struct and returned in %3, contradicting the nocapture semantics detailed here: LLVM Pointer Capture.
In the original issue reported LLVM Project Issue #93110, the problem likely occurs at the call site in the caller due to aggressive loop optimization, which misinterprets the nocapture attribute, leading to incorrect load hoisting.
It seems we may reconsider the nocapture annotation for the first property of the modify accessor, as its address might be aliased with the passed this pointer.
Environment
$ swift --version
Swift version 6.0-dev (LLVM e4f0051da337219, Swift c0af25c)
Target: x86_64-apple-macosx14.0
Additional information
No response
The text was updated successfully, but these errors were encountered:
kyulee-com
added
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
crash
Bug: A crash, i.e., an abnormal termination of software
triage needed
This issue needs more specific labels
labels
May 27, 2024
Ah, interesting. Yes, the nocapture attribute is not valid after Coro splitting. Coro splitting will take values "live across" a suspension point and store them into the coroutine frame. Coro splitting will split functions at suspension point into multiple functions. If the original parameter value is "live" in the second function it was spilled to the coroutine frame and the attribute is no longer valid.
LLVM's Coro splitting pass should remove the attribute.
I'm not familiar with this pass. Do you think we should conservatively remove the nocapture attribute from each parameter? I believe we also need to update the attributes of the arguments in the call instructions to these functions. Since this is a function pass, it seems we might require a module pass although we could simply update the users (call instructions) of the functions in place.
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwareSILGenArea → compiler: The SIL generation stage
Description
We experienced a runtime crash attributed to a hoisted load for
utf8ToString
in the SwiftProtobuf library. Initially suspecting a loop optimizer issue, I reported it here: LLVM Project Issue #93110. Based on the feedback, it seems that$ss7UnicodeO4UTF8O13ForwardParserVs10_UTFParserssAGP7_buffers11_UIntBufferVy8Encoding_8CodeUnitQZGvMTW
returns anocapture
pointer. This is demangled asprotocol witness for Swift._UTFParser._buffer.modify : Swift._UIntBuffer<A.Encoding.CodeUnit> in conformance Swift.Unicode.UTF8.ForwardParser : Swift._UTFParser in Swift
.The relevant code can be found in the Swift repository: UTF8.swift Code.
Reproduction
To isolate the issue, I used the following simplified code snippet and generated similar problematic code:
Command used:
Generated IR snippet:
Stack dump
Expected behavior
The
nocapture
attribute on the passed argument%1
seems to be violated as it is saved to a struct and returned in%3
, contradicting thenocapture
semantics detailed here: LLVM Pointer Capture.In the original issue reported LLVM Project Issue #93110, the problem likely occurs at the call site in the caller due to aggressive loop optimization, which misinterprets the
nocapture
attribute, leading to incorrect load hoisting.It seems we may reconsider the
nocapture
annotation for the first property of themodify
accessor, as its address might be aliased with the passedthis
pointer.Environment
$ swift --version
Swift version 6.0-dev (LLVM e4f0051da337219, Swift c0af25c)
Target: x86_64-apple-macosx14.0
Additional information
No response
The text was updated successfully, but these errors were encountered: