Coverage Report

Created: 2020-09-19 12:23

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugType.h
Line
Count
Source
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"
17
#include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
18
#include "clang/StaticAnalyzer/Core/Checker.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 CheckerNameRef CheckerName;
32
  const std::string Description;
33
  const std::string Category;
34
  const CheckerBase *Checker;
35
  bool SuppressOnSink;
36
37
  virtual void anchor();
38
39
public:
40
  BugType(CheckerNameRef CheckerName, StringRef Name, StringRef Cat,
41
          bool SuppressOnSink = false)
42
      : CheckerName(CheckerName), Description(Name), Category(Cat),
43
2.15k
        Checker(nullptr), SuppressOnSink(SuppressOnSink) {}
44
  BugType(const CheckerBase *Checker, StringRef Name, StringRef Cat,
45
          bool SuppressOnSink = false)
46
      : CheckerName(Checker->getCheckerName()), Description(Name),
47
3.58k
        Category(Cat), Checker(Checker), SuppressOnSink(SuppressOnSink) {}
48
5.74k
  virtual ~BugType() = default;
49
50
29.7k
  StringRef getDescription() const { return Description; }
51
28.9k
  StringRef getCategory() const { return Category; }
52
64.9k
  StringRef getCheckerName() const {
53
    // FIXME: This is a workaround to ensure that the correct checerk name is
54
    // used. The checker names are set after the constructors are run.
55
    // In case the BugType object is initialized in the checker's ctor
56
    // the CheckerName field will be empty. To circumvent this problem we use
57
    // CheckerBase whenever it is possible.
58
52.9k
    StringRef Ret = Checker ? Checker->getCheckerName() : 
CheckerName12.0k
;
59
64.9k
    assert(!Ret.empty() && "Checker name is not set properly.");
60
64.9k
    return Ret;
61
64.9k
  }
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
14.2k
  bool isSuppressOnSink() const { return SuppressOnSink; }
67
};
68
69
class BuiltinBug : public BugType {
70
  const std::string desc;
71
  void anchor() override;
72
public:
73
  BuiltinBug(class CheckerNameRef checker, const char *name,
74
             const char *description)
75
33
      : BugType(checker, name, categories::LogicError), desc(description) {}
76
77
  BuiltinBug(const CheckerBase *checker, const char *name,
78
             const char *description)
79
37
      : BugType(checker, name, categories::LogicError), desc(description) {}
80
81
  BuiltinBug(class CheckerNameRef checker, const char *name)
82
129
      : BugType(checker, name, categories::LogicError), desc(name) {}
83
84
  BuiltinBug(const CheckerBase *checker, const char *name)
85
485
      : BugType(checker, name, categories::LogicError), desc(name) {}
86
87
218
  StringRef getDescription() const { return desc; }
88
};
89
90
} // namespace ento
91
92
} // end clang namespace
93
#endif