llvm/clang/lib/StaticAnalyzer/Checkers/CXXDeleteChecker.cpp

//=== CXXDeleteChecker.cpp -------------------------------------*- C++ -*--===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines the following new checkers for C++ delete expressions:
//
//   * DeleteWithNonVirtualDtorChecker
//       Defines a checker for the OOP52-CPP CERT rule: Do not delete a
//       polymorphic object without a virtual destructor.
//
//       Diagnostic flags -Wnon-virtual-dtor and -Wdelete-non-virtual-dtor
//       report if an object with a virtual function but a non-virtual
//       destructor exists or is deleted, respectively.
//
//       This check exceeds them by comparing the dynamic and static types of
//       the object at the point of destruction and only warns if it happens
//       through a pointer to a base type without a virtual destructor. The
//       check places a note at the last point where the conversion from
//       derived to base happened.
//
//   * CXXArrayDeleteChecker
//       Defines a checker for the EXP51-CPP CERT rule: Do not delete an array
//       through a pointer of the incorrect type.
//
//===----------------------------------------------------------------------===//

#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
#include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicType.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"

usingnamespaceclang;
usingnamespaceento;

namespace {
class CXXDeleteChecker : public Checker<check::PreStmt<CXXDeleteExpr>> {};

class DeleteWithNonVirtualDtorChecker : public CXXDeleteChecker {};

class CXXArrayDeleteChecker : public CXXDeleteChecker {};
} // namespace

void CXXDeleteChecker::checkPreStmt(const CXXDeleteExpr *DE,
                                    CheckerContext &C) const {}

void DeleteWithNonVirtualDtorChecker::checkTypedDeleteExpr(
    const CXXDeleteExpr *DE, CheckerContext &C,
    const TypedValueRegion *BaseClassRegion,
    const SymbolicRegion *DerivedClassRegion) const {}

void CXXArrayDeleteChecker::checkTypedDeleteExpr(
    const CXXDeleteExpr *DE, CheckerContext &C,
    const TypedValueRegion *BaseClassRegion,
    const SymbolicRegion *DerivedClassRegion) const {}

PathDiagnosticPieceRef
CXXDeleteChecker::PtrCastVisitor::VisitNode(const ExplodedNode *N,
                                            BugReporterContext &BRC,
                                            PathSensitiveBugReport &BR) {}

void ento::registerArrayDeleteChecker(CheckerManager &mgr) {}

bool ento::shouldRegisterArrayDeleteChecker(const CheckerManager &mgr) {}

void ento::registerDeleteWithNonVirtualDtorChecker(CheckerManager &mgr) {}

bool ento::shouldRegisterDeleteWithNonVirtualDtorChecker(
    const CheckerManager &mgr) {}