| 1 | //===- BugSuppression.h - Suppression interface -----------------*- 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 BugSuppression, a simple interface class encapsulating |
| 10 | // all user provided in-code suppressions. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_SUPPRESSION_H |
| 15 | #define LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_SUPPRESSION_H |
| 16 | |
| 17 | #include "clang/Basic/SourceLocation.h" |
| 18 | #include "llvm/ADT/DenseMap.h" |
| 19 | #include "llvm/ADT/SmallVector.h" |
| 20 | |
| 21 | namespace clang { |
| 22 | class ASTContext; |
| 23 | class Decl; |
| 24 | |
| 25 | namespace ento { |
| 26 | class BugReport; |
| 27 | class PathDiagnosticLocation; |
| 28 | |
| 29 | class BugSuppression { |
| 30 | public: |
| 31 | explicit BugSuppression(const ASTContext &ACtx) : ACtx(ACtx) {} |
| 32 | |
| 33 | using DiagnosticIdentifierList = llvm::ArrayRef<llvm::StringRef>; |
| 34 | |
| 35 | /// Return true if the given bug report was explicitly suppressed by the user. |
| 36 | bool isSuppressed(const BugReport &); |
| 37 | |
| 38 | /// Return true if the bug reported at the given location was explicitly |
| 39 | /// suppressed by the user. |
| 40 | bool isSuppressed(const PathDiagnosticLocation &Location, |
| 41 | const Decl *DeclWithIssue, |
| 42 | DiagnosticIdentifierList DiagnosticIdentification); |
| 43 | |
| 44 | private: |
| 45 | // Overly pessimistic number, to be honest. |
| 46 | static constexpr unsigned EXPECTED_NUMBER_OF_SUPPRESSIONS = 8; |
| 47 | using CachedRanges = |
| 48 | llvm::SmallVector<SourceRange, EXPECTED_NUMBER_OF_SUPPRESSIONS>; |
| 49 | |
| 50 | llvm::DenseMap<const Decl *, CachedRanges> CachedSuppressionLocations; |
| 51 | |
| 52 | const ASTContext &ACtx; |
| 53 | }; |
| 54 | |
| 55 | } // end namespace ento |
| 56 | } // end namespace clang |
| 57 | |
| 58 | #endif // LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_SUPPRESSION_H |
| 59 | |