clang  9.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  bool SuppressOnSink=false)
43  : Check(Check), Name(Name), Category(Cat), Checker(nullptr),
44  SuppressOnSink(SuppressOnSink) {}
45  BugType(const CheckerBase *Checker, StringRef Name, StringRef Cat,
46  bool SuppressOnSink=false)
47  : Check(Checker->getCheckName()), Name(Name), Category(Cat),
48  Checker(Checker), SuppressOnSink(SuppressOnSink) {}
49  virtual ~BugType() = default;
50 
51  StringRef getName() const { return Name; }
52  StringRef getCategory() const { return Category; }
53  StringRef getCheckName() const {
54  // FIXME: This is a workaround to ensure that the correct check name is used
55  // The check names are set after the constructors are run.
56  // In case the BugType object is initialized in the checker's ctor
57  // the Check field will be empty. To circumvent this problem we use
58  // CheckerBase whenever it is possible.
59  StringRef CheckName =
60  Checker ? Checker->getCheckName().getName() : Check.getName();
61  assert(!CheckName.empty() && "Check name is not set properly.");
62  return CheckName;
63  }
64 
65  /// isSuppressOnSink - Returns true if bug reports associated with this bug
66  /// type should be suppressed if the end node of the report is post-dominated
67  /// by a sink node.
68  bool isSuppressOnSink() const { return SuppressOnSink; }
69 };
70 
71 class BuiltinBug : public BugType {
72  const std::string desc;
73  void anchor() override;
74 public:
75  BuiltinBug(class CheckName check, const char *name, const char *description)
76  : BugType(check, name, categories::LogicError), desc(description) {}
77 
78  BuiltinBug(const CheckerBase *checker, const char *name,
79  const char *description)
80  : BugType(checker, name, categories::LogicError), desc(description) {}
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 } // end ento namespace
89 
90 } // end clang namespace
91 #endif
BugType(CheckName Check, StringRef Name, StringRef Cat, bool SuppressOnSink=false)
Definition: BugType.h:41
BuiltinBug(class CheckName check, const char *name, const char *description)
Definition: BugType.h:75
BugType(const CheckerBase *Checker, StringRef Name, StringRef Cat, bool SuppressOnSink=false)
Definition: BugType.h:45
CheckName getCheckName() const
Definition: Checker.cpp:26
StringRef getDescription() const
Definition: BugType.h:85
StringRef getName() const
Definition: BugType.h:51
StringRef getCategory() const
Definition: BugType.h:52
BuiltinBug(const CheckerBase *checker, const char *name)
Definition: BugType.h:82
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
StringRef getName() const
Dataflow Directional Tag Classes.
virtual ~BugType()=default
StringRef getCheckName() const
Definition: BugType.h:53
bool isSuppressOnSink() const
isSuppressOnSink - Returns true if bug reports associated with this bug type should be suppressed if ...
Definition: BugType.h:68
BuiltinBug(const CheckerBase *checker, const char *name, const char *description)
Definition: BugType.h:78