[all-commits] [llvm/llvm-project] 673750: [LifetimeSafety] Implement a basic use-after-free ...

Utkarsh Saxena via All-commits all-commits at lists.llvm.org
Mon Aug 18 04:47:04 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 673750feea3a5506ec7cc6271596856dcebe88c4
      https://github.com/llvm/llvm-project/commit/673750feea3a5506ec7cc6271596856dcebe88c4
  Author: Utkarsh Saxena <usx at google.com>
  Date:   2025-08-18 (Mon, 18 Aug 2025)

  Changed paths:
    M clang/include/clang/Analysis/Analyses/LifetimeSafety.h
    M clang/include/clang/Basic/DiagnosticGroups.td
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/lib/Analysis/LifetimeSafety.cpp
    M clang/lib/Sema/AnalysisBasedWarnings.cpp
    A clang/test/Sema/warn-lifetime-safety.cpp
    M clang/unittests/Analysis/LifetimeSafetyTest.cpp

  Log Message:
  -----------
  [LifetimeSafety] Implement a basic use-after-free diagnostic (#149731)

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.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list