11573Srgrimes//===--- BugType.h - Bug Information Description ---------------*- C++ -*-===// 21573Srgrimes// 31573Srgrimes// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 41573Srgrimes// See https://llvm.org/LICENSE.txt for license information. 51573Srgrimes// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 61573Srgrimes// 71573Srgrimes//===----------------------------------------------------------------------===// 81573Srgrimes// 91573Srgrimes// This file defines BugType, a class representing a bug type. 101573Srgrimes// 111573Srgrimes//===----------------------------------------------------------------------===// 121573Srgrimes 131573Srgrimes#ifndef LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_BUGTYPE_H 141573Srgrimes#define LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_BUGTYPE_H 151573Srgrimes 16251069Semaste#include "clang/Basic/LLVM.h" 171573Srgrimes#include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h" 181573Srgrimes#include "clang/StaticAnalyzer/Core/Checker.h" 191573Srgrimes#include <string> 201573Srgrimes 211573Srgrimesnamespace clang { 221573Srgrimes 231573Srgrimesnamespace ento { 241573Srgrimes 251573Srgrimesclass BugReporter; 261573Srgrimes 271573Srgrimesclass BugType { 281573Srgrimesprivate: 291573Srgrimes const CheckerNameRef CheckerName; 301573Srgrimes const std::string Description; 311573Srgrimes const std::string Category; 321573Srgrimes const CheckerBase *Checker; 3350476Speter bool SuppressOnSink; 341573Srgrimes 35103165Swollman virtual void anchor(); 361573Srgrimes 371573Srgrimespublic: 381573Srgrimes BugType(CheckerNameRef CheckerName, StringRef Name, StringRef Cat, 39103165Swollman bool SuppressOnSink = false) 401573Srgrimes : CheckerName(CheckerName), Description(Name), Category(Cat), 4159460Sphantom Checker(nullptr), SuppressOnSink(SuppressOnSink) {} 4259460Sphantom BugType(const CheckerBase *Checker, StringRef Name, StringRef Cat, 431573Srgrimes bool SuppressOnSink = false) 4483206Sasmodai : CheckerName(Checker->getCheckerName()), Description(Name), 451573Srgrimes Category(Cat), Checker(Checker), SuppressOnSink(SuppressOnSink) {} 461573Srgrimes virtual ~BugType() = default; 47103165Swollman 48103165Swollman StringRef getDescription() const { return Description; } 491573Srgrimes StringRef getCategory() const { return Category; } 50103165Swollman StringRef getCheckerName() const { 51103165Swollman // FIXME: This is a workaround to ensure that the correct checerk name is 52103165Swollman // used. The checker names are set after the constructors are run. 53103165Swollman // In case the BugType object is initialized in the checker's ctor 54103165Swollman // the CheckerName field will be empty. To circumvent this problem we use 551573Srgrimes // CheckerBase whenever it is possible. 56103165Swollman StringRef Ret = Checker ? Checker->getCheckerName() : CheckerName; 57103165Swollman assert(!Ret.empty() && "Checker name is not set properly."); 58103165Swollman return Ret; 591573Srgrimes } 601573Srgrimes 611573Srgrimes /// isSuppressOnSink - Returns true if bug reports associated with this bug 621573Srgrimes /// type should be suppressed if the end node of the report is post-dominated 631573Srgrimes /// by a sink node. 641573Srgrimes bool isSuppressOnSink() const { return SuppressOnSink; } 651573Srgrimes}; 661573Srgrimes 671573Srgrimesclass BuiltinBug : public BugType { 681573Srgrimes const std::string desc; 691573Srgrimes void anchor() override; 701573Srgrimespublic: 711573Srgrimes BuiltinBug(class CheckerNameRef checker, const char *name, 721573Srgrimes const char *description) 7314964Sjoerg : BugType(checker, name, categories::LogicError), desc(description) {} 74103165Swollman 75103165Swollman BuiltinBug(const CheckerBase *checker, const char *name, 76103165Swollman const char *description) 77103165Swollman : BugType(checker, name, categories::LogicError), desc(description) {} 78103165Swollman 79103165Swollman BuiltinBug(class CheckerNameRef checker, const char *name) 80103165Swollman : BugType(checker, name, categories::LogicError), desc(name) {} 81103165Swollman 82103165Swollman BuiltinBug(const CheckerBase *checker, const char *name) 83103165Swollman : BugType(checker, name, categories::LogicError), desc(name) {} 84103165Swollman 85103165Swollman StringRef getDescription() const { return desc; } 86103165Swollman}; 87103165Swollman 88103165Swollman} // namespace ento 89103165Swollman 9049358Shoek} // end clang namespace 91103165Swollman#endif 92103165Swollman