Skip to content

[LifetimeSafety] Implement a basic use-after-free diagnostic #149731

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

Draft
wants to merge 1 commit into
base: users/usx95/07-14-users_usx95_lifetime-safety-add-loan-expiry
Choose a base branch
from

Conversation

usx95
Copy link
Contributor

@usx95 usx95 commented Jul 20, 2025

Implement use-after-free detection in the lifetime safety analysis with two warning levels.

  • Added a LifetimeSafetyReporter interface for reporting lifetime safety issues
  • Created two warning levels:
    • Definite errors (reported with -Wexperimental-lifetime-safety-permissive)
    • Potential errors (reported with -Wexperimental-lifetime-safety-strict)
  • Implemented a LifetimeChecker class that analyzes loan propagation and expired loans to detect use-after-free issues.
  • Added tracking of use sites through a new UseFact class.
  • Enhanced the ExpireFact to track the expressions where objects are destroyed.
  • Added test cases for both definite and potential use-after-free scenarios.

The implementation now tracks pointer uses and can determine when a pointer is dereferenced after its loan has been expired, with appropriate diagnostics.

The two warning levels provide flexibility - definite errors for high-confidence issues and potential errors for cases that depend on control flow.

Copy link
Contributor Author

usx95 commented Jul 20, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@usx95 usx95 changed the title basic error report for use after free [LifetimeSafety] Implement a basic use-after-free diagnostic Jul 20, 2025
@usx95 usx95 moved this to In Progress in Lifetime Safety in Clang Jul 20, 2025
@usx95 usx95 force-pushed the users/usx95/07-20-basic_error_report_for_use_after_free branch 2 times, most recently from a30dad1 to 8e3c34b Compare July 21, 2025 14:48
@usx95 usx95 force-pushed the users/usx95/07-14-users_usx95_lifetime-safety-add-loan-expiry branch 2 times, most recently from 6ad27da to 7ec322f Compare July 21, 2025 22:04
@usx95 usx95 force-pushed the users/usx95/07-20-basic_error_report_for_use_after_free branch from 8e3c34b to 2528e13 Compare July 21, 2025 22:07
@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
@usx95 usx95 force-pushed the users/usx95/07-20-basic_error_report_for_use_after_free branch from 2528e13 to 6ef046e Compare July 22, 2025 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

1 participant