-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[LifetimeSafety] Add missing origins stats for lifetime analysis #166568
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
Open
DEBADRIBASAK
wants to merge
21
commits into
llvm:main
Choose a base branch
from
DEBADRIBASAK:lifetime-stats
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
fd8693c
Adding the lifetime stats collection logic to AnalysisBasedWarnings
DEBADRIBASAK 3ff81d6
Correcting the signature of getMissingOrigins
DEBADRIBASAK 984582f
Merge branch 'main' into lifetime-stats
DEBADRIBASAK 499d3b0
Adding a LifetimeSafetyStats struct to keep track of missing origins …
DEBADRIBASAK f274e84
Merge branch 'main' into lifetime-stats
DEBADRIBASAK 8341778
Moving the missing origin calculation logic after lifetime analysis u…
DEBADRIBASAK 56b2dd9
Removing an outdated comment
DEBADRIBASAK 0081a95
Merge branch 'main' into lifetime-stats
DEBADRIBASAK 0ca0f58
Made MissingOriginCollector internal to Origins.cpp
DEBADRIBASAK a30fa2e
Introducing a dedicated file for LifetimeSafetyStats and changing the…
DEBADRIBASAK 8264809
Separating the StmtClassName and QualType for missing origin counts a…
DEBADRIBASAK 6f123ed
Removing unused headers from AnalysisBasedWarnings
DEBADRIBASAK 06f232e
Accepting LifetimeStats instead of individual maps inside Missingorig…
DEBADRIBASAK ea1eca9
Modified the LifetimeStats to use constant pointer to Type returned b…
DEBADRIBASAK f0d444c
Fomatting changes in variable names
DEBADRIBASAK cf92f90
Added a LIT test for missing origins stats and put a nullptr check in…
DEBADRIBASAK f0dab14
Merge branch 'main' into lifetime-stats
DEBADRIBASAK e03a850
Modifying the missing origin calculation logic after multi-origin tra…
DEBADRIBASAK 2f68912
Removing hasOrigin functions from LifetimeAnnotations. This logic is …
DEBADRIBASAK 0bf4b2f
Merge branch 'main' into lifetime-stats
DEBADRIBASAK 27a4b26
Merge branch 'main' into lifetime-stats
DEBADRIBASAK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
clang/include/clang/Analysis/Analyses/LifetimeSafety/LifetimeStats.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| //===- LifetimeStats.h - Lifetime Safety Statistics --------------*- C++-* -===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===------------------------------------------------------------------------===// | ||
| // | ||
| // This file declares the data structures and utility function for collection of | ||
| // statistics related to Lifetime Safety analysis. | ||
| // | ||
| //===------------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_LIFETIMESTATS_H | ||
| #define LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_LIFETIMESTATS_H | ||
|
|
||
| #include "clang/AST/TypeBase.h" | ||
| #include "llvm/ADT/DenseMap.h" | ||
| #include "llvm/ADT/StringMap.h" | ||
|
|
||
| namespace clang::lifetimes { | ||
| /// A structure to hold the statistics related to LifetimeAnalysis. | ||
| /// These are accumulated across all analyzed functions and printed | ||
| /// when -print-stats is enabled. | ||
| struct LifetimeSafetyStats { | ||
| /// A map from `StmtClassName` to their missing origin counts. | ||
| llvm::StringMap<unsigned> ExprStmtClassToMissingOriginCount; | ||
| /// A map from `QualType` to their missing origin counts. | ||
| llvm::DenseMap<const clang::Type *, unsigned> ExprTypeToMissingOriginCount; | ||
| }; | ||
|
|
||
| /// Utility function to print missing origin stats. | ||
| void printStats(const LifetimeSafetyStats &Stats); | ||
| } // namespace clang::lifetimes | ||
|
|
||
| #endif // LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_LIFETIMESTATS_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| //===- LifetimeStats.cpp - Lifetime Safety Statistics -*------------ C++-*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file defines the data structures and utility function for collection of | ||
| // staticstics related to Lifetimesafety analysis. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "clang/Analysis/Analyses/LifetimeSafety/LifetimeStats.h" | ||
| #include "clang/AST/TypeBase.h" | ||
| #include "llvm/Support/raw_ostream.h" | ||
|
|
||
| namespace clang::lifetimes { | ||
| void printStats(const LifetimeSafetyStats &Stats) { | ||
| llvm::errs() << "\n*** LifetimeSafety Missing Origin per QualType: " | ||
| "(QualType : count) :\n\n"; | ||
| unsigned TotalMissingOrigins = 0; | ||
| for (const auto &[ExprType, MissingOriginCount] : Stats.ExprTypeToMissingOriginCount) { | ||
| QualType QT = QualType(ExprType, 0); | ||
| llvm::errs() << QT.getAsString() << " : " << MissingOriginCount << '\n'; | ||
| TotalMissingOrigins += MissingOriginCount; | ||
| } | ||
| llvm::errs() << "\n\n*** LifetimeSafety Missing Origin per StmtClassName: " | ||
| "(StmtClassName : count) :\n\n"; | ||
| for (const auto &[ExprStmtClassName, MissingOriginCount] : Stats.ExprStmtClassToMissingOriginCount) { | ||
| llvm::errs() << ExprStmtClassName << " : " << MissingOriginCount << '\n'; | ||
| } | ||
| llvm::errs() << "\nTotal missing origins: " << TotalMissingOrigins << "\n"; | ||
| llvm::errs() << "\n****************************************\n"; | ||
| } | ||
| } // namespace clang::lifetimes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
clang/test/Sema/warn-lifetime-safety-missing-origin-stats.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // RUN: %clang_cc1 -print-stats -fexperimental-lifetime-safety -Wexperimental-lifetime-safety %s 2>&1 | FileCheck %s | ||
|
|
||
|
|
||
| // CHECK: *** LifetimeSafety Missing Origin per QualType: (QualType : count) : | ||
| // CHECK: *** LifetimeSafety Missing Origin per StmtClassName: (StmtClassName : count) : |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.