//===- BugReporter.h - Generate PathDiagnostics -----------------*- 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 BugReporter, a utility class for generating // PathDiagnostics for analyses based on ProgramState. // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_BUGREPORTER_H #define LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_BUGREPORTER_H #include "clang/Analysis/PathDiagnostic.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/SourceLocation.h" #include "clang/Lex/Preprocessor.h" #include "clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h" #include "clang/StaticAnalyzer/Core/BugReporter/BugSuppression.h" #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" #include "clang/StaticAnalyzer/Core/CheckerManager.h" #include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h" #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h" #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h" #include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/ImmutableSet.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/ilist.h" #include "llvm/ADT/ilist_node.h" #include "llvm/ADT/iterator_range.h" #include <cassert> #include <memory> #include <optional> #include <string> #include <utility> #include <vector> namespace clang { class AnalyzerOptions; class ASTContext; class Decl; class LocationContext; class SourceManager; class Stmt; namespace ento { class BugType; class CheckerBase; class ExplodedGraph; class ExplodedNode; class ExprEngine; class MemRegion; //===----------------------------------------------------------------------===// // Interface for individual bug reports. //===----------------------------------------------------------------------===// /// A mapping from diagnostic consumers to the diagnostics they should /// consume. DiagnosticForConsumerMapTy; /// Interface for classes constructing Stack hints. /// /// If a PathDiagnosticEvent occurs in a different frame than the final /// diagnostic the hints can be used to summarize the effect of the call. class StackHintGenerator { … }; /// Constructs a Stack hint for the given symbol. /// /// The class knows how to construct the stack hint message based on /// traversing the CallExpr associated with the call and checking if the given /// symbol is returned or is one of the arguments. /// The hint can be customized by redefining 'getMessageForX()' methods. class StackHintGeneratorForSymbol : public StackHintGenerator { … }; /// This class provides an interface through which checkers can create /// individual bug reports. class BugReport { … }; class BasicBugReport : public BugReport { … }; class PathSensitiveBugReport : public BugReport { … }; //===----------------------------------------------------------------------===// // BugTypes (collections of related reports). //===----------------------------------------------------------------------===// class BugReportEquivClass : public llvm::FoldingSetNode { … }; //===----------------------------------------------------------------------===// // BugReporter and friends. //===----------------------------------------------------------------------===// class BugReporterData { … }; /// BugReporter is a utility class for generating PathDiagnostics for analysis. /// It collects the BugReports and BugTypes and knows how to generate /// and flush the corresponding diagnostics. /// /// The base class is used for generating path-insensitive class BugReporter { … }; /// GRBugReporter is used for generating path-sensitive reports. class PathSensitiveBugReporter final : public BugReporter { … }; class BugReporterContext { … }; /// The tag that carries some information with it. /// /// It can be valuable to produce tags with some bits of information and later /// reuse them for a better diagnostic. /// /// Please make sure that derived class' constuctor is private and that the user /// can only create objects using DataTag::Factory. This also means that /// DataTag::Factory should be friend for every derived class. class DataTag : public ProgramPointTag { … }; /// The tag upon which the TagVisitor reacts. Add these in order to display /// additional PathDiagnosticEventPieces along the path. class NoteTag : public DataTag { … }; } // namespace ento } // namespace clang #endif // LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_BUGREPORTER_H