• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===---  BugType.h - Bug Information Desciption ----------------*- 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_ANALYSIS_BUGTYPE
15 #define LLVM_CLANG_ANALYSIS_BUGTYPE
16 
17 #include "clang/Basic/LLVM.h"
18 #include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
19 #include "clang/StaticAnalyzer/Core/Checker.h"
20 #include "llvm/ADT/FoldingSet.h"
21 #include <string>
22 
23 namespace clang {
24 
25 namespace ento {
26 
27 class BugReporter;
28 class ExplodedNode;
29 class ExprEngine;
30 
31 class BugType {
32 private:
33   const CheckName Check;
34   const std::string Name;
35   const std::string Category;
36   bool SuppressonSink;
37 
38   virtual void anchor();
39 public:
BugType(class CheckName check,StringRef name,StringRef cat)40   BugType(class CheckName check, StringRef name, StringRef cat)
41       : Check(check), Name(name), Category(cat), SuppressonSink(false) {}
BugType(const CheckerBase * checker,StringRef name,StringRef cat)42   BugType(const CheckerBase *checker, StringRef name, StringRef cat)
43       : Check(checker->getCheckName()), Name(name), Category(cat),
44         SuppressonSink(false) {}
~BugType()45   virtual ~BugType() {}
46 
47   // FIXME: Should these be made strings as well?
getName()48   StringRef getName() const { return Name; }
getCategory()49   StringRef getCategory() const { return Category; }
getCheckName()50   StringRef getCheckName() const { return Check.getName(); }
51 
52   /// isSuppressOnSink - Returns true if bug reports associated with this bug
53   ///  type should be suppressed if the end node of the report is post-dominated
54   ///  by a sink node.
isSuppressOnSink()55   bool isSuppressOnSink() const { return SuppressonSink; }
setSuppressOnSink(bool x)56   void setSuppressOnSink(bool x) { SuppressonSink = x; }
57 
58   virtual void FlushReports(BugReporter& BR);
59 };
60 
61 class BuiltinBug : public BugType {
62   const std::string desc;
63   void anchor() override;
64 public:
BuiltinBug(class CheckName check,const char * name,const char * description)65   BuiltinBug(class CheckName check, const char *name, const char *description)
66       : BugType(check, name, categories::LogicError), desc(description) {}
67 
BuiltinBug(const CheckerBase * checker,const char * name,const char * description)68   BuiltinBug(const CheckerBase *checker, const char *name,
69              const char *description)
70       : BugType(checker, name, categories::LogicError), desc(description) {}
71 
BuiltinBug(const CheckerBase * checker,const char * name)72   BuiltinBug(const CheckerBase *checker, const char *name)
73       : BugType(checker, name, categories::LogicError), desc(name) {}
74 
getDescription()75   StringRef getDescription() const { return desc; }
76 };
77 
78 } // end GR namespace
79 
80 } // end clang namespace
81 #endif
82