Skip to content

Commit 90b5537

Browse files
authored
Merge pull request #30 from haoNoQ/static-analyzer-cherrypicks-1
Clang Static Analyzer cherry-picks 1
2 parents 49e4ba6 + 7fb1a17 commit 90b5537

File tree

316 files changed

+13946
-5234
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

316 files changed

+13946
-5234
lines changed

clang-tools-extra/clang-tidy/ClangTidy.cpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@
3737
#include "clang/Rewrite/Frontend/FixItRewriter.h"
3838
#include "clang/Rewrite/Frontend/FrontendActions.h"
3939
#include "clang/Tooling/Core/Diagnostic.h"
40-
#if CLANG_ENABLE_STATIC_ANALYZER
41-
#include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
42-
#include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"
43-
#endif // CLANG_ENABLE_STATIC_ANALYZER
4440
#include "clang/Tooling/DiagnosticsYaml.h"
4541
#include "clang/Tooling/Refactoring.h"
4642
#include "clang/Tooling/ReplacementsYaml.h"
@@ -50,6 +46,11 @@
5046
#include <algorithm>
5147
#include <utility>
5248

49+
#if CLANG_ENABLE_STATIC_ANALYZER
50+
#include "clang/Analysis/PathDiagnostic.h"
51+
#include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"
52+
#endif // CLANG_ENABLE_STATIC_ANALYZER
53+
5354
using namespace clang::ast_matchers;
5455
using namespace clang::driver;
5556
using namespace clang::tooling;
@@ -72,7 +73,7 @@ class AnalyzerDiagnosticConsumer : public ento::PathDiagnosticConsumer {
7273
FilesMade *filesMade) override {
7374
for (const ento::PathDiagnostic *PD : Diags) {
7475
SmallString<64> CheckName(AnalyzerCheckNamePrefix);
75-
CheckName += PD->getCheckName();
76+
CheckName += PD->getCheckerName();
7677
Context.diag(CheckName, PD->getLocation().asLocation(),
7778
PD->getShortDescription())
7879
<< PD->path.back()->getRanges();
@@ -335,8 +336,8 @@ static void setStaticAnalyzerCheckerOpts(const ClangTidyOptions &Opts,
335336

336337
typedef std::vector<std::pair<std::string, bool>> CheckersList;
337338

338-
static CheckersList getCheckersControlList(ClangTidyContext &Context,
339-
bool IncludeExperimental) {
339+
static CheckersList getAnalyzerCheckersAndPackages(ClangTidyContext &Context,
340+
bool IncludeExperimental) {
340341
CheckersList List;
341342

342343
const auto &RegisteredCheckers =
@@ -420,9 +421,9 @@ ClangTidyASTConsumerFactory::CreateASTConsumer(
420421

421422
#if CLANG_ENABLE_STATIC_ANALYZER
422423
AnalyzerOptionsRef AnalyzerOptions = Compiler.getAnalyzerOpts();
423-
AnalyzerOptions->CheckersControlList =
424-
getCheckersControlList(Context, Context.canEnableAnalyzerAlphaCheckers());
425-
if (!AnalyzerOptions->CheckersControlList.empty()) {
424+
AnalyzerOptions->CheckersAndPackages = getAnalyzerCheckersAndPackages(
425+
Context, Context.canEnableAnalyzerAlphaCheckers());
426+
if (!AnalyzerOptions->CheckersAndPackages.empty()) {
426427
setStaticAnalyzerCheckerOpts(Context.getOptions(), AnalyzerOptions);
427428
AnalyzerOptions->AnalysisStoreOpt = RegionStoreModel;
428429
AnalyzerOptions->AnalysisDiagOpt = PD_NONE;
@@ -448,7 +449,7 @@ std::vector<std::string> ClangTidyASTConsumerFactory::getCheckNames() {
448449
}
449450

450451
#if CLANG_ENABLE_STATIC_ANALYZER
451-
for (const auto &AnalyzerCheck : getCheckersControlList(
452+
for (const auto &AnalyzerCheck : getAnalyzerCheckersAndPackages(
452453
Context, Context.canEnableAnalyzerAlphaCheckers()))
453454
CheckNames.push_back(AnalyzerCheckNamePrefix + AnalyzerCheck.first);
454455
#endif // CLANG_ENABLE_STATIC_ANALYZER

clang/docs/analyzer/checkers.rst

+9
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,15 @@ Check for values stored to variables that are never read afterwards.
260260
x = 1; // warn
261261
}
262262
263+
The ``WarnForDeadNestedAssignments`` option enables the checker to emit
264+
warnings for nested dead assignments. You can disable with the
265+
``-analyzer-config deadcode.DeadStores:WarnForDeadNestedAssignments=false``.
266+
*Defaults to true*.
267+
268+
Would warn for this e.g.:
269+
if ((y = make_int())) {
270+
}
271+
263272
.. _nullability-checkers:
264273
265274
nullability

clang/include/clang/AST/ASTImporter.h

+12
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ class TypeSourceInfo;
8686
using NonEquivalentDeclSet = llvm::DenseSet<std::pair<Decl *, Decl *>>;
8787
using ImportedCXXBaseSpecifierMap =
8888
llvm::DenseMap<const CXXBaseSpecifier *, CXXBaseSpecifier *>;
89+
using FileIDImportHandlerType =
90+
std::function<void(FileID /*ToID*/, FileID /*FromID*/)>;
8991

9092
enum class ODRHandlingType { Conservative, Liberal };
9193

@@ -211,6 +213,8 @@ class TypeSourceInfo;
211213
};
212214

213215
private:
216+
FileIDImportHandlerType FileIDImportHandler;
217+
214218
std::shared_ptr<ASTImporterSharedState> SharedState = nullptr;
215219

216220
/// The path which we go through during the import of a given AST node.
@@ -313,6 +317,14 @@ class TypeSourceInfo;
313317

314318
virtual ~ASTImporter();
315319

320+
/// Set a callback function for FileID import handling.
321+
/// The function is invoked when a FileID is imported from the From context.
322+
/// The imported FileID in the To context and the original FileID in the
323+
/// From context is passed to it.
324+
void setFileIDImportHandler(FileIDImportHandlerType H) {
325+
FileIDImportHandler = H;
326+
}
327+
316328
/// Whether the importer will perform a minimal import, creating
317329
/// to-be-completed forward declarations when possible.
318330
bool isMinimalImport() const { return Minimal; }

clang/include/clang/AST/Type.h

+3
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,9 @@ class QualType {
972972
friend bool operator!=(const QualType &LHS, const QualType &RHS) {
973973
return LHS.Value != RHS.Value;
974974
}
975+
friend bool operator<(const QualType &LHS, const QualType &RHS) {
976+
return LHS.Value < RHS.Value;
977+
}
975978

976979
static std::string getAsString(SplitQualType split,
977980
const PrintingPolicy &Policy) {

0 commit comments

Comments
 (0)