I've added some unit tests in my PR, and they are triggering LinearLifetimeChecker. This seems to be an existing issue, not related to my changes, but reproducible by newly added tests. Reported as A leak due to a consuming post-dominance failure · Issue #91645 · swiftlang/swift · GitHub.
When running tests with --param swift_test_mode=optimize_none_with_opaque_values function convertDirectToIndirectFunctionArgs() inserts a load_borrow in the beginning of the function, and end_borrow in all function-existing blocks. But unreachable block does not count as function-exiting, and non end_borrow is inserted, which LinearLifetimeChecker complains about.
What would be the best way to fix it?
- Teach
LinearLifetimeCheckerto ignore unreachable blocks. - Insert
end_borrowby maintaining separate list of program-ending blocks (don't changepass.exitingInsts). - Insert
end_borrowby insertingunreachable-terminated blocks intopass.exitingInsts, updateOpaqueValueVisitor::canonicalizeReturnValues(),ReturnRewriter::rewriteReturns()andReturnRewriter::rewriteThrows()to expectUnreachableInst. - Return true from
isFunctionExiting()forUnreachableInst, update even more code.
So far, I'm leaning towards 2.
WDYT?