Skip to content

Conversation

@steakhal
Copy link

@steakhal steakhal commented Dec 1, 2025

Objective-C blocks are like lambdas. They have captures, just like lambdas. However, they can also implicitly capture themselves unlike lambdas.

This means that when walking the captures of a block, we may end up in infinite recursion. This is not possible with lambdas, but happened in practice with blocks downstream.

In this patch, I just use a set to keep track of the visited MemRegions.

Note that theoretically, there is nothing preventing usual lambdas or functors from falling for the same trap, but probably slightly more difficult to do so. You would likely need a pointer to itself, etc. I'll not speculate here.

This inf recursion was likely caused by llvm#126620, released in clang-21.

rdar://162215172
(cherry picked from commit 30b1d14)

…encing blocks (llvm#169208)

Objective-C blocks are like lambdas. They have captures, just like lambdas.
However, they can also implicitly capture themselves unlike lambdas.

This means that when walking the captures of a block, we may end up in
infinite recursion. This is not possible with lambdas, but happened in
practice with blocks downstream.

In this patch, I just use a set to keep track of the visited MemRegions.

Note that theoretically, there is nothing preventing usual lambdas or
functors from falling for the same trap, but probably slightly more
difficult to do so. You would likely need a pointer to itself, etc. I'll
not speculate here.

This inf recursion was likely caused by llvm#126620, released in clang-21.

rdar://162215172
(cherry picked from commit 30b1d14)
@steakhal steakhal requested a review from a team as a code owner December 1, 2025 18:37
@steakhal
Copy link
Author

steakhal commented Dec 2, 2025

@ziqingluo-90 Any testing needed? I saw on one of your previous PRs that you issued commands.

@steakhal
Copy link
Author

steakhal commented Dec 3, 2025

@swift-ci test llvm

@steakhal
Copy link
Author

steakhal commented Dec 3, 2025

@swift-ci test linux
@swift-ci test macos
@swift-ci test windows

@steakhal
Copy link
Author

steakhal commented Dec 3, 2025

@swift-ci test linux

@steakhal
Copy link
Author

steakhal commented Dec 3, 2025

@swift-ci test macOS

@steakhal steakhal merged commit d519e7d into stable/21.x Dec 4, 2025
5 checks passed
@steakhal steakhal deleted the steakhal/eng-162215172-cherrypick branch December 4, 2025 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants