clang  10.0.0svn
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 class ExplodedNode;
27 class ExprEngine;
28 
29 class BugType {
30 private:
31  const CheckName Check;
32  const std::string Name;
33  const std::string Category;
34  const CheckerBase *Checker;
35  bool SuppressOnSink;
36 
37  virtual void anchor();
38 
39 public:
40  BugType(CheckName Check, StringRef Name, StringRef Cat,
41  bool SuppressOnSink=false)
42  : Check(Check), Name(Name), Category(Cat), Checker(nullptr),
43  SuppressOnSink(SuppressOnSink) {}
44  BugType(const CheckerBase *Checker, StringRef Name, StringRef Cat,
45  bool SuppressOnSink=false)
46  : Check(Checker->getCheckName()), Name(Name), Category(Cat),
47  Checker(Checker), SuppressOnSink(SuppressOnSink) {}
48  virtual ~BugType() = default;
49 
50  StringRef getName() const { return Name; }
51  StringRef getCategory() const { return Category; }
52  StringRef getCheckName() const {
53  // FIXME: This is a workaround to ensure that the correct check name is used
54  // The check names are set after the constructors are run.
55  // In case the BugType object is initialized in the checker's ctor
56  // the Check field will be empty. To circumvent this problem we use
57  // CheckerBase whenever it is possible.
58  StringRef CheckName =
59  Checker ? Checker->getCheckName().getName() : Check.getName();
60  assert(!CheckName.empty() && "Check name is not set properly.");
61  return CheckName;
62  }
63 
64  /// isSuppressOnSink - Returns true if bug reports associated with this bug
65  /// type should be suppressed if the end node of the report is post-dominated
66  /// by a sink node.
67  bool isSuppressOnSink() const { return SuppressOnSink; }
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
BugType(CheckName Check, StringRef Name, StringRef Cat, bool SuppressOnSink=false)
Definition: BugType.h:40
BuiltinBug(class CheckName check, const char *name, const char *description)
Definition: BugType.h:74
BugType(const CheckerBase *Checker, StringRef Name, StringRef Cat, bool SuppressOnSink=false)
Definition: BugType.h:44
CheckName getCheckName() const
Definition: Checker.cpp:25
RangeSelector name(std::string ID)
Given a node with a "name", (like NamedDecl, DeclRefExpr or CxxCtorInitializer) selects the name&#39;s to...
StringRef getDescription() const
Definition: BugType.h:84
StringRef getName() const
Definition: BugType.h:50
StringRef getCategory() const
Definition: BugType.h:51
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...
StringRef getName() const
Dataflow Directional Tag Classes.
virtual ~BugType()=default
StringRef getCheckName() const
Definition: BugType.h:52
bool isSuppressOnSink() const
isSuppressOnSink - Returns true if bug reports associated with this bug type should be suppressed if ...
Definition: BugType.h:67
BuiltinBug(const CheckerBase *checker, const char *name, const char *description)
Definition: BugType.h:77