//===- ReturnValueChecker - Check methods always returning true -*- 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 defines ReturnValueChecker, which models a very specific coding // convention within the LLVM/Clang codebase: there several classes that have // Error() methods which always return true. // This checker was introduced to eliminate false positives caused by this // peculiar "always returns true" invariant. (Normally, the analyzer assumes // that a function returning `bool` can return both `true` and `false`, because // otherwise it could've been a `void` function.) // //===----------------------------------------------------------------------===// #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" #include "clang/StaticAnalyzer/Core/Checker.h" #include "clang/StaticAnalyzer/Core/CheckerManager.h" #include "clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h" #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h" #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/FormatVariadic.h" #include <optional> usingnamespaceclang; usingnamespaceento; formatv; namespace { class ReturnValueChecker : public Checker<check::PostCall> { … }; } // namespace static std::string getName(const CallEvent &Call) { … } void ReturnValueChecker::checkPostCall(const CallEvent &Call, CheckerContext &C) const { … } void ento::registerReturnValueChecker(CheckerManager &Mgr) { … } bool ento::shouldRegisterReturnValueChecker(const CheckerManager &mgr) { … }