clang 23.0.0git
OpaqueSTLFunctionsModeling.cpp
Go to the documentation of this file.
1//===--- OpaqueSTLFunctionsModeling.cpp -----------------------------------===//
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// Models STL functions whose best accurate model is to invalidate their
10// arguments. Only functions where this simple approach is sufficient and won't
11// interfere with the modeling of other checkers should be put here.
12//
13//===----------------------------------------------------------------------===//
14
20
21using namespace clang;
22using namespace ento;
23
24namespace {
25class OpaqueSTLFunctionsModeling : public Checker<eval::Call> {
26public:
27 bool evalCall(const CallEvent &Call, CheckerContext &C) const;
28
29private:
30 const CallDescriptionSet ModeledFunctions{
31 {CDM::SimpleFunc, {"std", "sort"}},
32 {CDM::SimpleFunc, {"std", "stable_sort"}},
33 {CDM::SimpleFunc, {"std", "inplace_merge"}}};
34};
35} // namespace
36
37bool OpaqueSTLFunctionsModeling::evalCall(const CallEvent &Call,
38 CheckerContext &C) const {
39 if (!ModeledFunctions.contains(Call))
40 return false;
41
42 ProgramStateRef InvalidatedRegionsState =
43 Call.invalidateRegions(C.blockCount(), C.getState());
44 C.addTransition(InvalidatedRegionsState);
45 return true;
46}
47
48void ento::registerOpaqueSTLFunctionsModeling(CheckerManager &Mgr) {
49 Mgr.registerChecker<OpaqueSTLFunctionsModeling>();
50}
51
52bool ento::shouldRegisterOpaqueSTLFunctionsModeling(const CheckerManager &Mgr) {
53 return Mgr.getLangOpts().CPlusPlus;
54}
bool contains(const CallEvent &Call) const
Represents an abstract call to a function or method along a particular path.
Definition CallEvent.h:153
CHECKER * registerChecker(AT &&...Args)
Register a single-part checker (derived from Checker): construct its singleton instance,...
const LangOptions & getLangOpts() const
Simple checker classes that implement one frontend (i.e.
Definition Checker.h:553
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
The JSON file list parser is used to communicate input to InstallAPI.