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 27 class BugType { 28 private: 29 const CheckerNameRef CheckerName; 30 const std::string Description; 31 const std::string Category; 32 const CheckerBase *Checker; 33 bool SuppressOnSink; 34 35 virtual void anchor(); 36 37 public: 38 BugType(CheckerNameRef CheckerName, StringRef Desc, 39 StringRef Cat = categories::LogicError, bool SuppressOnSink = false) CheckerName(CheckerName)40 : CheckerName(CheckerName), Description(Desc), Category(Cat), 41 Checker(nullptr), SuppressOnSink(SuppressOnSink) {} 42 BugType(const CheckerBase *Checker, StringRef Desc, 43 StringRef Cat = categories::LogicError, bool SuppressOnSink = false) 44 : CheckerName(Checker->getCheckerName()), Description(Desc), 45 Category(Cat), Checker(Checker), SuppressOnSink(SuppressOnSink) {} 46 virtual ~BugType() = default; 47 getDescription()48 StringRef getDescription() const { return Description; } getCategory()49 StringRef getCategory() const { return Category; } getCheckerName()50 StringRef getCheckerName() const { 51 // FIXME: This is a workaround to ensure that the correct checerk name is 52 // used. The checker names are set after the constructors are run. 53 // In case the BugType object is initialized in the checker's ctor 54 // the CheckerName field will be empty. To circumvent this problem we use 55 // CheckerBase whenever it is possible. 56 StringRef Ret = Checker ? Checker->getCheckerName() : CheckerName; 57 assert(!Ret.empty() && "Checker name is not set properly."); 58 return Ret; 59 } 60 61 /// isSuppressOnSink - Returns true if bug reports associated with this bug 62 /// type should be suppressed if the end node of the report is post-dominated 63 /// by a sink node. isSuppressOnSink()64 bool isSuppressOnSink() const { return SuppressOnSink; } 65 }; 66 67 } // namespace ento 68 69 } // end clang namespace 70 #endif 71