-
Notifications
You must be signed in to change notification settings - Fork 424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code in defer block is run after deinitializer #14797
Comments
To make sure I'm understanding: The assertion is that it's more correct to have the defer block run first and then the local variable initialization, is that right? It seems this was the case in 1.20 (TIO). Has it changed since then? |
Yes. The issue is that |
* Resolves issue chapel-lang#14797 * Adds testing * Uses slightly faster C++ std::map calls in a few places and avoids adding to the map for outer variables.
Improve expiring value analysis This PR makes two improvements to expiring value analysis. * It updates the analysis to consider variables mentioned in a defer statement to expire at the end-of-block. This resolves issue #14797. * It changes the logic for inserting into the map detecting captures. Now, a capture will not be detected before the variable it is describing is initialized. This resolves a problem I had not noticed with the I/O example from issue #11492. I also updated the test to output the array that was read, so that it will be more obvious if this pattern fails again. Resolves #14797. Reviewed by @benharsh - thanks! - [x] full local testing
Summary of Problem
The code contained in a defer block is run after deinitializers for any local variables created in the same scope.
I expect the opposite to be true (defer blocks run first).
Steps to Reproduce
Reproducer courtesy of @mppf:
Note that taking a reference to the variable or avoiding use of a defer block both seem to fix this issue.
The text was updated successfully, but these errors were encountered: