Skip to content

[LifetimeSafety] Add loan expiry analysis #148712

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

Merged

Conversation

usx95
Copy link
Contributor

@usx95 usx95 commented Jul 14, 2025

This PR adds the ExpiredLoansAnalysis class to track which loans have expired. The analysis uses a dataflow lattice (ExpiredLattice) to maintain the set of expired loans at each program point.

This is a very light weight dataflow analysis and is expected to reach fixed point in ~2 iterations.
In principle, this does not need a dataflow analysis but is used for convenience in favour of lean code.

Copy link
Contributor Author

usx95 commented Jul 14, 2025

@usx95 usx95 changed the title users/usx95/lifetime-safety-add-loan-expiry [LifetimeSafety] Add loan expiry analysis Jul 14, 2025
@usx95 usx95 force-pushed the users/usx95/07-14-users_usx95_lifetime-safety-add-loan-expiry branch from 880cf3b to ed73e3b Compare July 14, 2025 19:49
@usx95 usx95 force-pushed the users/usx95/lifetime-safety-liveness branch from c217d0d to 702d255 Compare July 14, 2025 19:49
@usx95 usx95 force-pushed the users/usx95/07-14-users_usx95_lifetime-safety-add-loan-expiry branch from ed73e3b to a50b00e Compare July 14, 2025 19:52
@usx95 usx95 force-pushed the users/usx95/lifetime-safety-liveness branch 2 times, most recently from 7e098b0 to 793d58e Compare July 14, 2025 20:02
@usx95 usx95 force-pushed the users/usx95/07-14-users_usx95_lifetime-safety-add-loan-expiry branch from a50b00e to a9f1e8d Compare July 14, 2025 20:03
@usx95 usx95 self-assigned this Jul 14, 2025
@usx95 usx95 force-pushed the users/usx95/lifetime-safety-liveness branch from 793d58e to 2bff132 Compare July 15, 2025 09:09
@usx95 usx95 force-pushed the users/usx95/07-14-users_usx95_lifetime-safety-add-loan-expiry branch 5 times, most recently from 6ce3173 to 9265536 Compare July 15, 2025 10:27
@usx95 usx95 force-pushed the users/usx95/lifetime-safety-liveness branch from 2253ff0 to c073ef3 Compare July 15, 2025 10:27
@usx95 usx95 force-pushed the users/usx95/07-14-users_usx95_lifetime-safety-add-loan-expiry branch from 9265536 to 9da8f3a Compare July 15, 2025 10:47
@usx95 usx95 force-pushed the users/usx95/lifetime-safety-liveness branch from c073ef3 to 51afc3e Compare July 15, 2025 10:47
@usx95 usx95 force-pushed the users/usx95/07-14-users_usx95_lifetime-safety-add-loan-expiry branch from 9da8f3a to 04d6193 Compare July 15, 2025 17:53
@usx95 usx95 force-pushed the users/usx95/lifetime-safety-liveness branch from 51afc3e to 7b26a72 Compare July 15, 2025 17:53
@usx95 usx95 force-pushed the users/usx95/07-14-users_usx95_lifetime-safety-add-loan-expiry branch from 04d6193 to 2073937 Compare July 15, 2025 21:33
@usx95 usx95 changed the base branch from users/usx95/lifetime-safety-liveness to users/usx95/07-15-add-backward-analysis-capability July 15, 2025 21:35
@usx95 usx95 force-pushed the users/usx95/07-14-users_usx95_lifetime-safety-add-loan-expiry branch 2 times, most recently from 5f09913 to aca68c2 Compare July 15, 2025 21:54
@usx95 usx95 force-pushed the users/usx95/07-15-add-backward-analysis-capability branch from b109b6a to 7502ee5 Compare July 15, 2025 21:54
@usx95 usx95 requested a review from jvoung July 15, 2025 22:03
@usx95 usx95 force-pushed the users/usx95/07-14-users_usx95_lifetime-safety-add-loan-expiry branch from 7365fc4 to a7d03b1 Compare July 16, 2025 22:10
@usx95 usx95 changed the base branch from main to users/usx95/07-16-lifetime-safety-add-unit-tests July 17, 2025 17:47
@usx95 usx95 force-pushed the users/usx95/07-14-users_usx95_lifetime-safety-add-loan-expiry branch from a7d03b1 to d5b093e Compare July 17, 2025 17:48
@usx95 usx95 force-pushed the users/usx95/07-14-users_usx95_lifetime-safety-add-loan-expiry branch from d5b093e to 70b63ed Compare July 17, 2025 18:54
@usx95 usx95 force-pushed the users/usx95/07-16-lifetime-safety-add-unit-tests branch from 16fccbd to 3e0b53f Compare July 17, 2025 18:54
@usx95 usx95 force-pushed the users/usx95/07-14-users_usx95_lifetime-safety-add-loan-expiry branch 2 times, most recently from 9a3a69a to 8c5c8f1 Compare July 18, 2025 11:57
@usx95 usx95 force-pushed the users/usx95/07-16-lifetime-safety-add-unit-tests branch from 3e0b53f to e6fc855 Compare July 18, 2025 11:57
@usx95 usx95 force-pushed the users/usx95/07-14-users_usx95_lifetime-safety-add-loan-expiry branch from 8c5c8f1 to c29040a Compare July 18, 2025 14:27
@usx95 usx95 requested a review from Xazax-hun July 18, 2025 14:28
@usx95
Copy link
Contributor Author

usx95 commented Jul 18, 2025

Added unit tests for loan expiry!

@@ -832,6 +833,65 @@ class LoanPropagationAnalysis
}
};

// ========================================================================= //
// Expired Loans Analysis
// ========================================================================= //
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add dash.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a suggestion? I don't quite get the location where you are referring.

}

Lattice transfer(Lattice In, const IssueFact &F) {
return Lattice(Factory.remove(In.Expired, F.getLoanID()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth explaining why this is necessary. Specifically, now its possible that the loan would appear in In.Expired at all to be worth removing. I assume this arises because of backedges.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. There is a subtle false negative due to this as well. Mentioned that.

Copy link
Collaborator

@Xazax-hun Xazax-hun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the comments are addressed it looks good to me.

@usx95 usx95 force-pushed the users/usx95/07-14-users_usx95_lifetime-safety-add-loan-expiry branch from c29040a to 6ad27da Compare July 21, 2025 14:48
@usx95 usx95 force-pushed the users/usx95/07-16-lifetime-safety-add-unit-tests branch from e6fc855 to ad8d8a8 Compare July 21, 2025 22:04
@usx95 usx95 force-pushed the users/usx95/07-14-users_usx95_lifetime-safety-add-loan-expiry branch from 6ad27da to 7ec322f Compare July 21, 2025 22:05
Base automatically changed from users/usx95/07-16-lifetime-safety-add-unit-tests to main July 22, 2025 10:32
@usx95 usx95 force-pushed the users/usx95/07-14-users_usx95_lifetime-safety-add-loan-expiry branch from 7ec322f to 65f5402 Compare July 22, 2025 10:33
Copy link
Contributor

@jvoung jvoung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG too!

@usx95 usx95 force-pushed the users/usx95/07-14-users_usx95_lifetime-safety-add-loan-expiry branch from 65f5402 to 7a78e40 Compare July 23, 2025 09:53
Copy link
Contributor Author

usx95 commented Jul 23, 2025

Merge activity

  • Jul 23, 10:12 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jul 23, 10:14 AM UTC: @usx95 merged this pull request with Graphite.

@usx95 usx95 merged commit ffdada1 into main Jul 23, 2025
7 of 9 checks passed
@usx95 usx95 deleted the users/usx95/07-14-users_usx95_lifetime-safety-add-loan-expiry branch July 23, 2025 10:14
@github-project-automation github-project-automation bot moved this from In Progress to Done in Lifetime Safety in Clang Jul 23, 2025
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Jul 28, 2025
This PR adds the `ExpiredLoansAnalysis` class to track which loans have expired. The analysis uses a dataflow lattice (`ExpiredLattice`) to maintain the set of expired loans at each program point.

This is a very light weight dataflow analysis and is expected to reach fixed point in ~2 iterations.
In principle, this does not need a dataflow analysis but is used for convenience in favour of lean code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:analysis clang Clang issues not falling into any other category
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants