1 //===--- BugType.h - Bug Information Description ---------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines BugType, a class representing a bug type.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_BUGTYPE_H
15 #define LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_BUGTYPE_H
17 #include "clang/Basic/LLVM.h"
18 #include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
19 #include "clang/StaticAnalyzer/Core/Checker.h"
32 const CheckName Check;
33 const std::string Name;
34 const std::string Category;
35 const CheckerBase *Checker;
38 virtual void anchor();
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;
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.
58 Checker ? Checker->getCheckName().getName() : Check.getName();
59 assert(!CheckName.empty() && "Check name is not set properly.");
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
66 bool isSuppressOnSink() const { return SuppressOnSink; }
67 void setSuppressOnSink(bool x) { SuppressOnSink = x; }
69 virtual void FlushReports(BugReporter& BR);
72 class BuiltinBug : public BugType {
73 const std::string desc;
74 void anchor() override;
76 BuiltinBug(class CheckName check, const char *name, const char *description)
77 : BugType(check, name, categories::LogicError), desc(description) {}
79 BuiltinBug(const CheckerBase *checker, const char *name,
80 const char *description)
81 : BugType(checker, name, categories::LogicError), desc(description) {}
83 BuiltinBug(const CheckerBase *checker, const char *name)
84 : BugType(checker, name, categories::LogicError), desc(name) {}
86 StringRef getDescription() const { return desc; }
89 } // end ento namespace
91 } // end clang namespace