clang  8.0.0svn
BugType.h
Go to the documentation of this file.
1 //===--- BugType.h - Bug Information Description ---------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines BugType, a class representing a bug type.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_BUGTYPE_H
15 #define LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_BUGTYPE_H
16 
17 #include "clang/Basic/LLVM.h"
20 #include <string>
21 
22 namespace clang {
23 
24 namespace ento {
25 
26 class BugReporter;
27 class ExplodedNode;
28 class ExprEngine;
29 
30 class BugType {
31 private:
32  const CheckName Check;
33  const std::string Name;
34  const std::string Category;
35  const CheckerBase *Checker;
36  bool SuppressOnSink;
37 
38  virtual void anchor();
39 
40 public:
41  BugType(CheckName Check, StringRef Name, StringRef Cat)
42  : Check(Check), Name(Name), Category(Cat), Checker(nullptr),
43  SuppressOnSink(false) {}
44  BugType(const CheckerBase *Checker, StringRef Name, StringRef Cat)
45  : Check(Checker->getCheckName()), Name(Name), Category(Cat),
46  Checker(Checker), SuppressOnSink(false) {}
47  virtual ~BugType() = default;
48 
49  StringRef getName() const { return Name; }
50  StringRef getCategory() const { return Category; }
51  StringRef getCheckName() const {
52  // FIXME: This is a workaround to ensure that the correct check name is used
53  // The check names are set after the constructors are run.
54  // In case the BugType object is initialized in the checker's ctor
55  // the Check field will be empty. To circumvent this problem we use
56  // CheckerBase whenever it is possible.
57  StringRef CheckName =
58  Checker ? Checker->getCheckName().getName() : Check.getName();
59  assert(!CheckName.empty() && "Check name is not set properly.");
60  return CheckName;
61  }
62 
63  /// isSuppressOnSink - Returns true if bug reports associated with this bug
64  /// type should be suppressed if the end node of the report is post-dominated
65  /// by a sink node.
66  bool isSuppressOnSink() const { return SuppressOnSink; }
67  void setSuppressOnSink(bool x) { SuppressOnSink = x; }
68 };
69 
70 class BuiltinBug : public BugType {
71  const std::string desc;
72  void anchor() override;
73 public:
74  BuiltinBug(class CheckName check, const char *name, const char *description)
75  : BugType(check, name, categories::LogicError), desc(description) {}
76 
77  BuiltinBug(const CheckerBase *checker, const char *name,
78  const char *description)
79  : BugType(checker, name, categories::LogicError), desc(description) {}
80 
81  BuiltinBug(const CheckerBase *checker, const char *name)
82  : BugType(checker, name, categories::LogicError), desc(name) {}
83 
84  StringRef getDescription() const { return desc; }
85 };
86 
87 } // end ento namespace
88 
89 } // end clang namespace
90 #endif
BuiltinBug(class CheckName check, const char *name, const char *description)
Definition: BugType.h:74
BugType(const CheckerBase *Checker, StringRef Name, StringRef Cat)
Definition: BugType.h:44
CheckName getCheckName() const
Definition: Checker.cpp:24
StringRef getDescription() const
Definition: BugType.h:84
StringRef getName() const
Definition: BugType.h:49
StringRef getCategory() const
Definition: BugType.h:50
BuiltinBug(const CheckerBase *checker, const char *name)
Definition: BugType.h:81
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
void setSuppressOnSink(bool x)
Definition: BugType.h:67
StringRef getName() const
#define false
Definition: stdbool.h:33
Dataflow Directional Tag Classes.
virtual ~BugType()=default
StringRef getCheckName() const
Definition: BugType.h:51
BugType(CheckName Check, StringRef Name, StringRef Cat)
Definition: BugType.h:41
bool isSuppressOnSink() const
isSuppressOnSink - Returns true if bug reports associated with this bug type should be suppressed if ...
Definition: BugType.h:66
BuiltinBug(const CheckerBase *checker, const char *name, const char *description)
Definition: BugType.h:77