clang  15.0.0git
BugType.h
Go to the documentation of this file.
1 //===--- BugType.h - Bug Information Description ---------------*- 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 BugType, a class representing a bug type.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_BUGTYPE_H
14 #define LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_BUGTYPE_H
15 
16 #include "clang/Basic/LLVM.h"
19 #include <string>
20 
21 namespace clang {
22 
23 namespace ento {
24 
25 class BugReporter;
26 
27 class BugType {
28 private:
29  const CheckerNameRef CheckerName;
30  const std::string Description;
31  const std::string Category;
32  const CheckerBase *Checker;
33  bool SuppressOnSink;
34 
35  virtual void anchor();
36 
37 public:
38  BugType(CheckerNameRef CheckerName, StringRef Name, StringRef Cat,
39  bool SuppressOnSink = false)
40  : CheckerName(CheckerName), Description(Name), Category(Cat),
41  Checker(nullptr), SuppressOnSink(SuppressOnSink) {}
42  BugType(const CheckerBase *Checker, StringRef Name, StringRef Cat,
43  bool SuppressOnSink = false)
44  : CheckerName(Checker->getCheckerName()), Description(Name),
45  Category(Cat), Checker(Checker), SuppressOnSink(SuppressOnSink) {}
46  virtual ~BugType() = default;
47 
48  StringRef getDescription() const { return Description; }
49  StringRef getCategory() const { return Category; }
50  StringRef getCheckerName() const {
51  // FIXME: This is a workaround to ensure that the correct checerk name is
52  // used. The checker names are set after the constructors are run.
53  // In case the BugType object is initialized in the checker's ctor
54  // the CheckerName field will be empty. To circumvent this problem we use
55  // CheckerBase whenever it is possible.
56  StringRef Ret = Checker ? Checker->getCheckerName() : CheckerName;
57  assert(!Ret.empty() && "Checker name is not set properly.");
58  return Ret;
59  }
60 
61  /// isSuppressOnSink - Returns true if bug reports associated with this bug
62  /// type should be suppressed if the end node of the report is post-dominated
63  /// by a sink node.
64  bool isSuppressOnSink() const { return SuppressOnSink; }
65 };
66 
67 class BuiltinBug : public BugType {
68  const std::string desc;
69  void anchor() override;
70 public:
71  BuiltinBug(class CheckerNameRef checker, const char *name,
72  const char *description)
73  : BugType(checker, name, categories::LogicError), desc(description) {}
74 
75  BuiltinBug(const CheckerBase *checker, const char *name,
76  const char *description)
77  : BugType(checker, name, categories::LogicError), desc(description) {}
78 
79  BuiltinBug(class CheckerNameRef checker, const char *name)
80  : BugType(checker, name, categories::LogicError), desc(name) {}
81 
82  BuiltinBug(const CheckerBase *checker, const char *name)
83  : BugType(checker, name, categories::LogicError), desc(name) {}
84 
85  StringRef getDescription() const { return desc; }
86 };
87 
88 } // namespace ento
89 
90 } // end clang namespace
91 #endif
clang::ento::BugType::BugType
BugType(const CheckerBase *Checker, StringRef Name, StringRef Cat, bool SuppressOnSink=false)
Definition: BugType.h:42
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
Ret
static bool Ret(InterpState &S, CodePtr &PC, APValue &Result)
Definition: Interp.cpp:34
clang::ento::BugType::getCheckerName
StringRef getCheckerName() const
Definition: BugType.h:50
clang::ento::BuiltinBug::BuiltinBug
BuiltinBug(class CheckerNameRef checker, const char *name, const char *description)
Definition: BugType.h:71
clang::ento::BuiltinBug::BuiltinBug
BuiltinBug(const CheckerBase *checker, const char *name, const char *description)
Definition: BugType.h:75
clang::ento::BugType::isSuppressOnSink
bool isSuppressOnSink() const
isSuppressOnSink - Returns true if bug reports associated with this bug type should be suppressed if ...
Definition: BugType.h:64
clang::ento::CheckerBase::getCheckerName
CheckerNameRef getCheckerName() const
Definition: Checker.cpp:25
clang::ento::BuiltinBug::BuiltinBug
BuiltinBug(const CheckerBase *checker, const char *name)
Definition: BugType.h:82
CommonBugCategories.h
clang::ento::BugType::BugType
BugType(CheckerNameRef CheckerName, StringRef Name, StringRef Cat, bool SuppressOnSink=false)
Definition: BugType.h:38
clang::ento::BugType::getDescription
StringRef getDescription() const
Definition: BugType.h:48
clang::ento::BuiltinBug
Definition: BugType.h:67
clang::ento::BugType
Definition: BugType.h:27
clang::ento::CheckerNameRef
This wrapper is used to ensure that only StringRefs originating from the CheckerRegistry are used as ...
Definition: CheckerManager.h:106
Category
int Category
Definition: Format.cpp:2575
clang::ento::CheckerBase
Definition: Checker.h:492
LLVM.h
Checker.h
clang::ento::categories::LogicError
const char *const LogicError
Definition: CommonBugCategories.cpp:17
clang
Definition: CalledOnceCheck.h:17
clang::ento::BuiltinBug::getDescription
StringRef getDescription() const
Definition: BugType.h:85
clang::ento::BugType::~BugType
virtual ~BugType()=default
clang::ento::Checker
Definition: Checker.h:517
clang::ento::BugType::getCategory
StringRef getCategory() const
Definition: BugType.h:49
clang::ento::BuiltinBug::BuiltinBug
BuiltinBug(class CheckerNameRef checker, const char *name)
Definition: BugType.h:79
clang::transformer::name
RangeSelector name(std::string ID)
Given a node with a "name", (like NamedDecl, DeclRefExpr, CxxCtorInitializer, and TypeLoc) selects th...
Definition: RangeSelector.cpp:200