Coverage Report

Created: 2018-07-19 20:53

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h
Line
Count
Source
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"
18
#include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
19
#include "clang/StaticAnalyzer/Core/Checker.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
698
        SuppressOnSink(false) {}
44
  BugType(const CheckerBase *Checker, StringRef Name, StringRef Cat)
45
      : Check(Checker->getCheckName()), Name(Name), Category(Cat),
46
950
        Checker(Checker), SuppressOnSink(false) {}
47
1.64k
  virtual ~BugType() = default;
48
49
10.2k
  StringRef getName() const { return Name; }
50
10.2k
  StringRef getCategory() const { return Category; }
51
10.2k
  StringRef getCheckName() const {
52
10.2k
    // FIXME: This is a workaround to ensure that the correct check name is used
53
10.2k
    // The check names are set after the constructors are run.
54
10.2k
    // In case the BugType object is initialized in the checker's ctor
55
10.2k
    // the Check field will be empty. To circumvent this problem we use 
56
10.2k
    // CheckerBase whenever it is possible.
57
10.2k
    StringRef CheckName =
58
10.2k
        Checker ? 
Checker->getCheckName().getName()8.40k
:
Check.getName()1.80k
;
59
10.2k
    assert(!CheckName.empty() && "Check name is not set properly.");
60
10.2k
    return CheckName;
61
10.2k
  }
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
9.78k
  bool isSuppressOnSink() const { return SuppressOnSink; }
67
105
  void setSuppressOnSink(bool x) { SuppressOnSink = x; }
68
69
  virtual void FlushReports(BugReporter& BR);
70
};
71
72
class BuiltinBug : public BugType {
73
  const std::string desc;
74
  void anchor() override;
75
public:
76
  BuiltinBug(class CheckName check, const char *name, const char *description)
77
28
      : BugType(check, name, categories::LogicError), desc(description) {}
78
79
  BuiltinBug(const CheckerBase *checker, const char *name,
80
             const char *description)
81
40
      : BugType(checker, name, categories::LogicError), desc(description) {}
82
83
  BuiltinBug(const CheckerBase *checker, const char *name)
84
378
      : BugType(checker, name, categories::LogicError), desc(name) {}
85
86
171
  StringRef getDescription() const { return desc; }
87
};
88
89
} // end ento namespace
90
91
} // end clang namespace
92
#endif