Skip to content

Commit 2eb8c47

Browse files
authored
[LifetimeSafety] Reorganize code into modular components (#162474)
Restructure the C++ Lifetime Safety Analysis into modular components with clear separation of concerns. This PR reorganizes the C++ Lifetime Safety Analysis code by: 1. Breaking up the monolithic `LifetimeSafety.cpp` (1500+ lines) into multiple smaller, focused files 2. Creating a dedicated `LifetimeSafety` directory with a clean component structure 3. Introducing header files for each component with proper documentation 4. Moving existing code into the appropriate component files: - `Checker.h/cpp`: Core lifetime checking logic - `Dataflow.h`: Generic dataflow analysis framework - `Facts.h`: Lifetime-relevant events and fact management - `FactsGenerator.h/cpp`: AST traversal for fact generation - `LiveOrigins.h/cpp`: Backward dataflow analysis for origin liveness - `LoanPropagation.h/cpp`: Forward dataflow analysis for loan tracking - `Loans.h`: Loan and access path definitions - `Origins.h`: Origin management - `Reporter.h`: Interface for reporting lifetime violations - `Utils.h`: Common utilities for the analysis The code functionality remains the same, but is now better organized with clearer interfaces between components.
1 parent 1c5bba1 commit 2eb8c47

31 files changed

+2207
-1754
lines changed

.github/new-prs-labeler.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,8 +1096,8 @@ clang:openmp:
10961096
- llvm/test/Transforms/OpenMP/**
10971097

10981098
clang:temporal-safety:
1099-
- clang/include/clang/Analysis/Analyses/LifetimeSafety*
1100-
- clang/lib/Analysis/LifetimeSafety*
1099+
- clang/include/clang/Analysis/Analyses/LifetimeSafety/**
1100+
- clang/lib/Analysis/LifetimeSafety/**
11011101
- clang/unittests/Analysis/LifetimeSafety*
11021102
- clang/test/Sema/*lifetime-safety*
11031103
- clang/test/Sema/*lifetime-analysis*

clang/include/clang/Analysis/Analyses/LifetimeSafety.h

Lines changed: 0 additions & 183 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===- Checker.h - C++ Lifetime Safety Analysis -*----------- C++-*-=========//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file defines and enforces the lifetime safety policy. It detects
10+
// use-after-free errors by examining loan expiration points and checking if
11+
// any live origins hold the expired loans.
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#ifndef LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_CHECKER_H
16+
#define LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_CHECKER_H
17+
18+
#include "clang/Analysis/Analyses/LifetimeSafety/Facts.h"
19+
#include "clang/Analysis/Analyses/LifetimeSafety/LifetimeSafety.h"
20+
#include "clang/Analysis/Analyses/LifetimeSafety/LiveOrigins.h"
21+
#include "clang/Analysis/Analyses/LifetimeSafety/LoanPropagation.h"
22+
23+
namespace clang::lifetimes::internal {
24+
25+
/// Runs the lifetime checker, which detects use-after-free errors by
26+
/// examining loan expiration points and checking if any live origins hold
27+
/// the expired loan.
28+
void runLifetimeChecker(const LoanPropagationAnalysis &LoanPropagation,
29+
const LiveOriginsAnalysis &LiveOrigins,
30+
const FactManager &FactMgr, AnalysisDeclContext &ADC,
31+
LifetimeSafetyReporter *Reporter);
32+
33+
} // namespace clang::lifetimes::internal
34+
35+
#endif // LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_CHECKER_H

0 commit comments

Comments
 (0)