xref: /freebsd/contrib/llvm-project/clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp (revision fe6060f10f634930ff71b7c50291ddc610da2475)
10b57cec5SDimitry Andric //=== InnerPointerChecker.cpp -------------------------------------*- C++ -*--//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file defines a check that marks a raw pointer to a C++ container's
100b57cec5SDimitry Andric // inner buffer released when the object is destroyed. This information can
110b57cec5SDimitry Andric // be used by MallocChecker to detect use-after-free problems.
120b57cec5SDimitry Andric //
130b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
140b57cec5SDimitry Andric 
150b57cec5SDimitry Andric #include "AllocationState.h"
160b57cec5SDimitry Andric #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
170b57cec5SDimitry Andric #include "InterCheckerAPI.h"
180b57cec5SDimitry Andric #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
190b57cec5SDimitry Andric #include "clang/StaticAnalyzer/Core/BugReporter/CommonBugCategories.h"
200b57cec5SDimitry Andric #include "clang/StaticAnalyzer/Core/Checker.h"
210b57cec5SDimitry Andric #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
220b57cec5SDimitry Andric #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
230b57cec5SDimitry Andric 
240b57cec5SDimitry Andric using namespace clang;
250b57cec5SDimitry Andric using namespace ento;
260b57cec5SDimitry Andric 
270b57cec5SDimitry Andric // Associate container objects with a set of raw pointer symbols.
280b57cec5SDimitry Andric REGISTER_SET_FACTORY_WITH_PROGRAMSTATE(PtrSet, SymbolRef)
290b57cec5SDimitry Andric REGISTER_MAP_WITH_PROGRAMSTATE(RawPtrMap, const MemRegion *, PtrSet)
300b57cec5SDimitry Andric 
310b57cec5SDimitry Andric 
320b57cec5SDimitry Andric namespace {
330b57cec5SDimitry Andric 
340b57cec5SDimitry Andric class InnerPointerChecker
350b57cec5SDimitry Andric     : public Checker<check::DeadSymbols, check::PostCall> {
360b57cec5SDimitry Andric 
37*fe6060f1SDimitry Andric   CallDescription AppendFn, AssignFn, AddressofFn, ClearFn, CStrFn, DataFn,
38*fe6060f1SDimitry Andric       DataMemberFn, EraseFn, InsertFn, PopBackFn, PushBackFn, ReplaceFn,
39*fe6060f1SDimitry Andric       ReserveFn, ResizeFn, ShrinkToFitFn, SwapFn;
400b57cec5SDimitry Andric 
410b57cec5SDimitry Andric public:
420b57cec5SDimitry Andric   class InnerPointerBRVisitor : public BugReporterVisitor {
430b57cec5SDimitry Andric     SymbolRef PtrToBuf;
440b57cec5SDimitry Andric 
450b57cec5SDimitry Andric   public:
460b57cec5SDimitry Andric     InnerPointerBRVisitor(SymbolRef Sym) : PtrToBuf(Sym) {}
470b57cec5SDimitry Andric 
480b57cec5SDimitry Andric     static void *getTag() {
490b57cec5SDimitry Andric       static int Tag = 0;
500b57cec5SDimitry Andric       return &Tag;
510b57cec5SDimitry Andric     }
520b57cec5SDimitry Andric 
530b57cec5SDimitry Andric     void Profile(llvm::FoldingSetNodeID &ID) const override {
540b57cec5SDimitry Andric       ID.AddPointer(getTag());
550b57cec5SDimitry Andric     }
560b57cec5SDimitry Andric 
57a7dea167SDimitry Andric     virtual PathDiagnosticPieceRef
58a7dea167SDimitry Andric     VisitNode(const ExplodedNode *N, BugReporterContext &BRC,
59a7dea167SDimitry Andric               PathSensitiveBugReport &BR) override;
600b57cec5SDimitry Andric 
610b57cec5SDimitry Andric     // FIXME: Scan the map once in the visitor's constructor and do a direct
620b57cec5SDimitry Andric     // lookup by region.
630b57cec5SDimitry Andric     bool isSymbolTracked(ProgramStateRef State, SymbolRef Sym) {
640b57cec5SDimitry Andric       RawPtrMapTy Map = State->get<RawPtrMap>();
65480093f4SDimitry Andric       for (const auto &Entry : Map) {
660b57cec5SDimitry Andric         if (Entry.second.contains(Sym))
670b57cec5SDimitry Andric           return true;
680b57cec5SDimitry Andric       }
690b57cec5SDimitry Andric       return false;
700b57cec5SDimitry Andric     }
710b57cec5SDimitry Andric   };
720b57cec5SDimitry Andric 
730b57cec5SDimitry Andric   InnerPointerChecker()
740b57cec5SDimitry Andric       : AppendFn({"std", "basic_string", "append"}),
750b57cec5SDimitry Andric         AssignFn({"std", "basic_string", "assign"}),
76*fe6060f1SDimitry Andric         AddressofFn({"std", "addressof"}),
770b57cec5SDimitry Andric         ClearFn({"std", "basic_string", "clear"}),
78*fe6060f1SDimitry Andric         CStrFn({"std", "basic_string", "c_str"}), DataFn({"std", "data"}, 1),
79*fe6060f1SDimitry Andric         DataMemberFn({"std", "basic_string", "data"}),
800b57cec5SDimitry Andric         EraseFn({"std", "basic_string", "erase"}),
810b57cec5SDimitry Andric         InsertFn({"std", "basic_string", "insert"}),
820b57cec5SDimitry Andric         PopBackFn({"std", "basic_string", "pop_back"}),
830b57cec5SDimitry Andric         PushBackFn({"std", "basic_string", "push_back"}),
840b57cec5SDimitry Andric         ReplaceFn({"std", "basic_string", "replace"}),
850b57cec5SDimitry Andric         ReserveFn({"std", "basic_string", "reserve"}),
860b57cec5SDimitry Andric         ResizeFn({"std", "basic_string", "resize"}),
870b57cec5SDimitry Andric         ShrinkToFitFn({"std", "basic_string", "shrink_to_fit"}),
880b57cec5SDimitry Andric         SwapFn({"std", "basic_string", "swap"}) {}
890b57cec5SDimitry Andric 
900b57cec5SDimitry Andric   /// Check whether the called member function potentially invalidates
910b57cec5SDimitry Andric   /// pointers referring to the container object's inner buffer.
920b57cec5SDimitry Andric   bool isInvalidatingMemberFunction(const CallEvent &Call) const;
930b57cec5SDimitry Andric 
94*fe6060f1SDimitry Andric   /// Check whether the called function returns a raw inner pointer.
95*fe6060f1SDimitry Andric   bool isInnerPointerAccessFunction(const CallEvent &Call) const;
96*fe6060f1SDimitry Andric 
970b57cec5SDimitry Andric   /// Mark pointer symbols associated with the given memory region released
980b57cec5SDimitry Andric   /// in the program state.
990b57cec5SDimitry Andric   void markPtrSymbolsReleased(const CallEvent &Call, ProgramStateRef State,
1000b57cec5SDimitry Andric                               const MemRegion *ObjRegion,
1010b57cec5SDimitry Andric                               CheckerContext &C) const;
1020b57cec5SDimitry Andric 
1030b57cec5SDimitry Andric   /// Standard library functions that take a non-const `basic_string` argument by
1040b57cec5SDimitry Andric   /// reference may invalidate its inner pointers. Check for these cases and
1050b57cec5SDimitry Andric   /// mark the pointers released.
1060b57cec5SDimitry Andric   void checkFunctionArguments(const CallEvent &Call, ProgramStateRef State,
1070b57cec5SDimitry Andric                               CheckerContext &C) const;
1080b57cec5SDimitry Andric 
1090b57cec5SDimitry Andric   /// Record the connection between raw pointers referring to a container
1100b57cec5SDimitry Andric   /// object's inner buffer and the object's memory region in the program state.
1110b57cec5SDimitry Andric   /// Mark potentially invalidated pointers released.
1120b57cec5SDimitry Andric   void checkPostCall(const CallEvent &Call, CheckerContext &C) const;
1130b57cec5SDimitry Andric 
1140b57cec5SDimitry Andric   /// Clean up the program state map.
1150b57cec5SDimitry Andric   void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
1160b57cec5SDimitry Andric };
1170b57cec5SDimitry Andric 
1180b57cec5SDimitry Andric } // end anonymous namespace
1190b57cec5SDimitry Andric 
1200b57cec5SDimitry Andric bool InnerPointerChecker::isInvalidatingMemberFunction(
1210b57cec5SDimitry Andric         const CallEvent &Call) const {
1220b57cec5SDimitry Andric   if (const auto *MemOpCall = dyn_cast<CXXMemberOperatorCall>(&Call)) {
1230b57cec5SDimitry Andric     OverloadedOperatorKind Opc = MemOpCall->getOriginExpr()->getOperator();
1240b57cec5SDimitry Andric     if (Opc == OO_Equal || Opc == OO_PlusEqual)
1250b57cec5SDimitry Andric       return true;
1260b57cec5SDimitry Andric     return false;
1270b57cec5SDimitry Andric   }
1280b57cec5SDimitry Andric   return (isa<CXXDestructorCall>(Call) || Call.isCalled(AppendFn) ||
1290b57cec5SDimitry Andric           Call.isCalled(AssignFn) || Call.isCalled(ClearFn) ||
1300b57cec5SDimitry Andric           Call.isCalled(EraseFn) || Call.isCalled(InsertFn) ||
1310b57cec5SDimitry Andric           Call.isCalled(PopBackFn) || Call.isCalled(PushBackFn) ||
1320b57cec5SDimitry Andric           Call.isCalled(ReplaceFn) || Call.isCalled(ReserveFn) ||
1330b57cec5SDimitry Andric           Call.isCalled(ResizeFn) || Call.isCalled(ShrinkToFitFn) ||
1340b57cec5SDimitry Andric           Call.isCalled(SwapFn));
1350b57cec5SDimitry Andric }
1360b57cec5SDimitry Andric 
137*fe6060f1SDimitry Andric bool InnerPointerChecker::isInnerPointerAccessFunction(
138*fe6060f1SDimitry Andric     const CallEvent &Call) const {
139*fe6060f1SDimitry Andric   return (Call.isCalled(CStrFn) || Call.isCalled(DataFn) ||
140*fe6060f1SDimitry Andric           Call.isCalled(DataMemberFn));
141*fe6060f1SDimitry Andric }
142*fe6060f1SDimitry Andric 
1430b57cec5SDimitry Andric void InnerPointerChecker::markPtrSymbolsReleased(const CallEvent &Call,
1440b57cec5SDimitry Andric                                                  ProgramStateRef State,
1450b57cec5SDimitry Andric                                                  const MemRegion *MR,
1460b57cec5SDimitry Andric                                                  CheckerContext &C) const {
1470b57cec5SDimitry Andric   if (const PtrSet *PS = State->get<RawPtrMap>(MR)) {
1480b57cec5SDimitry Andric     const Expr *Origin = Call.getOriginExpr();
1490b57cec5SDimitry Andric     for (const auto Symbol : *PS) {
1500b57cec5SDimitry Andric       // NOTE: `Origin` may be null, and will be stored so in the symbol's
1510b57cec5SDimitry Andric       // `RefState` in MallocChecker's `RegionState` program state map.
1520b57cec5SDimitry Andric       State = allocation_state::markReleased(State, Symbol, Origin);
1530b57cec5SDimitry Andric     }
1540b57cec5SDimitry Andric     State = State->remove<RawPtrMap>(MR);
1550b57cec5SDimitry Andric     C.addTransition(State);
1560b57cec5SDimitry Andric     return;
1570b57cec5SDimitry Andric   }
1580b57cec5SDimitry Andric }
1590b57cec5SDimitry Andric 
1600b57cec5SDimitry Andric void InnerPointerChecker::checkFunctionArguments(const CallEvent &Call,
1610b57cec5SDimitry Andric                                                  ProgramStateRef State,
1620b57cec5SDimitry Andric                                                  CheckerContext &C) const {
1630b57cec5SDimitry Andric   if (const auto *FC = dyn_cast<AnyFunctionCall>(&Call)) {
1640b57cec5SDimitry Andric     const FunctionDecl *FD = FC->getDecl();
1650b57cec5SDimitry Andric     if (!FD || !FD->isInStdNamespace())
1660b57cec5SDimitry Andric       return;
1670b57cec5SDimitry Andric 
1680b57cec5SDimitry Andric     for (unsigned I = 0, E = FD->getNumParams(); I != E; ++I) {
1690b57cec5SDimitry Andric       QualType ParamTy = FD->getParamDecl(I)->getType();
1700b57cec5SDimitry Andric       if (!ParamTy->isReferenceType() ||
1710b57cec5SDimitry Andric           ParamTy->getPointeeType().isConstQualified())
1720b57cec5SDimitry Andric         continue;
1730b57cec5SDimitry Andric 
1740b57cec5SDimitry Andric       // In case of member operator calls, `this` is counted as an
1750b57cec5SDimitry Andric       // argument but not as a parameter.
1760b57cec5SDimitry Andric       bool isaMemberOpCall = isa<CXXMemberOperatorCall>(FC);
1770b57cec5SDimitry Andric       unsigned ArgI = isaMemberOpCall ? I+1 : I;
1780b57cec5SDimitry Andric 
1790b57cec5SDimitry Andric       SVal Arg = FC->getArgSVal(ArgI);
1800b57cec5SDimitry Andric       const auto *ArgRegion =
1810b57cec5SDimitry Andric           dyn_cast_or_null<TypedValueRegion>(Arg.getAsRegion());
1820b57cec5SDimitry Andric       if (!ArgRegion)
1830b57cec5SDimitry Andric         continue;
1840b57cec5SDimitry Andric 
185*fe6060f1SDimitry Andric       // std::addressof function accepts a non-const reference as an argument,
186*fe6060f1SDimitry Andric       // but doesn't modify it.
187*fe6060f1SDimitry Andric       if (Call.isCalled(AddressofFn))
188*fe6060f1SDimitry Andric         continue;
189*fe6060f1SDimitry Andric 
1900b57cec5SDimitry Andric       markPtrSymbolsReleased(Call, State, ArgRegion, C);
1910b57cec5SDimitry Andric     }
1920b57cec5SDimitry Andric   }
1930b57cec5SDimitry Andric }
1940b57cec5SDimitry Andric 
1950b57cec5SDimitry Andric // [string.require]
1960b57cec5SDimitry Andric //
1970b57cec5SDimitry Andric // "References, pointers, and iterators referring to the elements of a
1980b57cec5SDimitry Andric // basic_string sequence may be invalidated by the following uses of that
1990b57cec5SDimitry Andric // basic_string object:
2000b57cec5SDimitry Andric //
2010b57cec5SDimitry Andric // -- As an argument to any standard library function taking a reference
2020b57cec5SDimitry Andric // to non-const basic_string as an argument. For example, as an argument to
2030b57cec5SDimitry Andric // non-member functions swap(), operator>>(), and getline(), or as an argument
2040b57cec5SDimitry Andric // to basic_string::swap().
2050b57cec5SDimitry Andric //
2060b57cec5SDimitry Andric // -- Calling non-const member functions, except operator[], at, front, back,
2070b57cec5SDimitry Andric // begin, rbegin, end, and rend."
2080b57cec5SDimitry Andric 
2090b57cec5SDimitry Andric void InnerPointerChecker::checkPostCall(const CallEvent &Call,
2100b57cec5SDimitry Andric                                         CheckerContext &C) const {
2110b57cec5SDimitry Andric   ProgramStateRef State = C.getState();
2120b57cec5SDimitry Andric 
2130b57cec5SDimitry Andric   // TODO: Do we need these to be typed?
214*fe6060f1SDimitry Andric   const TypedValueRegion *ObjRegion = nullptr;
215*fe6060f1SDimitry Andric 
216*fe6060f1SDimitry Andric   if (const auto *ICall = dyn_cast<CXXInstanceCall>(&Call)) {
217*fe6060f1SDimitry Andric     ObjRegion = dyn_cast_or_null<TypedValueRegion>(
2180b57cec5SDimitry Andric         ICall->getCXXThisVal().getAsRegion());
219*fe6060f1SDimitry Andric 
220*fe6060f1SDimitry Andric     // Check [string.require] / second point.
221*fe6060f1SDimitry Andric     if (isInvalidatingMemberFunction(Call)) {
222*fe6060f1SDimitry Andric       markPtrSymbolsReleased(Call, State, ObjRegion, C);
223*fe6060f1SDimitry Andric       return;
224*fe6060f1SDimitry Andric     }
225*fe6060f1SDimitry Andric   }
226*fe6060f1SDimitry Andric 
227*fe6060f1SDimitry Andric   if (isInnerPointerAccessFunction(Call)) {
228*fe6060f1SDimitry Andric 
229*fe6060f1SDimitry Andric     if (isa<SimpleFunctionCall>(Call)) {
230*fe6060f1SDimitry Andric       // NOTE: As of now, we only have one free access function: std::data.
231*fe6060f1SDimitry Andric       //       If we add more functions like this in the list, hardcoded
232*fe6060f1SDimitry Andric       //       argument index should be changed.
233*fe6060f1SDimitry Andric       ObjRegion =
234*fe6060f1SDimitry Andric           dyn_cast_or_null<TypedValueRegion>(Call.getArgSVal(0).getAsRegion());
235*fe6060f1SDimitry Andric     }
236*fe6060f1SDimitry Andric 
2370b57cec5SDimitry Andric     if (!ObjRegion)
2380b57cec5SDimitry Andric       return;
2390b57cec5SDimitry Andric 
2400b57cec5SDimitry Andric     SVal RawPtr = Call.getReturnValue();
2410b57cec5SDimitry Andric     if (SymbolRef Sym = RawPtr.getAsSymbol(/*IncludeBaseRegions=*/true)) {
2420b57cec5SDimitry Andric       // Start tracking this raw pointer by adding it to the set of symbols
2430b57cec5SDimitry Andric       // associated with this container object in the program state map.
2440b57cec5SDimitry Andric 
2450b57cec5SDimitry Andric       PtrSet::Factory &F = State->getStateManager().get_context<PtrSet>();
2460b57cec5SDimitry Andric       const PtrSet *SetPtr = State->get<RawPtrMap>(ObjRegion);
2470b57cec5SDimitry Andric       PtrSet Set = SetPtr ? *SetPtr : F.getEmptySet();
2480b57cec5SDimitry Andric       assert(C.wasInlined || !Set.contains(Sym));
2490b57cec5SDimitry Andric       Set = F.add(Set, Sym);
2500b57cec5SDimitry Andric 
2510b57cec5SDimitry Andric       State = State->set<RawPtrMap>(ObjRegion, Set);
2520b57cec5SDimitry Andric       C.addTransition(State);
2530b57cec5SDimitry Andric     }
2540b57cec5SDimitry Andric 
2550b57cec5SDimitry Andric     return;
2560b57cec5SDimitry Andric   }
2570b57cec5SDimitry Andric 
2580b57cec5SDimitry Andric   // Check [string.require] / first point.
2590b57cec5SDimitry Andric   checkFunctionArguments(Call, State, C);
2600b57cec5SDimitry Andric }
2610b57cec5SDimitry Andric 
2620b57cec5SDimitry Andric void InnerPointerChecker::checkDeadSymbols(SymbolReaper &SymReaper,
2630b57cec5SDimitry Andric                                            CheckerContext &C) const {
2640b57cec5SDimitry Andric   ProgramStateRef State = C.getState();
2650b57cec5SDimitry Andric   PtrSet::Factory &F = State->getStateManager().get_context<PtrSet>();
2660b57cec5SDimitry Andric   RawPtrMapTy RPM = State->get<RawPtrMap>();
267480093f4SDimitry Andric   for (const auto &Entry : RPM) {
2680b57cec5SDimitry Andric     if (!SymReaper.isLiveRegion(Entry.first)) {
2690b57cec5SDimitry Andric       // Due to incomplete destructor support, some dead regions might
2700b57cec5SDimitry Andric       // remain in the program state map. Clean them up.
2710b57cec5SDimitry Andric       State = State->remove<RawPtrMap>(Entry.first);
2720b57cec5SDimitry Andric     }
2730b57cec5SDimitry Andric     if (const PtrSet *OldSet = State->get<RawPtrMap>(Entry.first)) {
2740b57cec5SDimitry Andric       PtrSet CleanedUpSet = *OldSet;
2750b57cec5SDimitry Andric       for (const auto Symbol : Entry.second) {
2760b57cec5SDimitry Andric         if (!SymReaper.isLive(Symbol))
2770b57cec5SDimitry Andric           CleanedUpSet = F.remove(CleanedUpSet, Symbol);
2780b57cec5SDimitry Andric       }
2790b57cec5SDimitry Andric       State = CleanedUpSet.isEmpty()
2800b57cec5SDimitry Andric                   ? State->remove<RawPtrMap>(Entry.first)
2810b57cec5SDimitry Andric                   : State->set<RawPtrMap>(Entry.first, CleanedUpSet);
2820b57cec5SDimitry Andric     }
2830b57cec5SDimitry Andric   }
2840b57cec5SDimitry Andric   C.addTransition(State);
2850b57cec5SDimitry Andric }
2860b57cec5SDimitry Andric 
2870b57cec5SDimitry Andric namespace clang {
2880b57cec5SDimitry Andric namespace ento {
2890b57cec5SDimitry Andric namespace allocation_state {
2900b57cec5SDimitry Andric 
2910b57cec5SDimitry Andric std::unique_ptr<BugReporterVisitor> getInnerPointerBRVisitor(SymbolRef Sym) {
292a7dea167SDimitry Andric   return std::make_unique<InnerPointerChecker::InnerPointerBRVisitor>(Sym);
2930b57cec5SDimitry Andric }
2940b57cec5SDimitry Andric 
2950b57cec5SDimitry Andric const MemRegion *getContainerObjRegion(ProgramStateRef State, SymbolRef Sym) {
2960b57cec5SDimitry Andric   RawPtrMapTy Map = State->get<RawPtrMap>();
297480093f4SDimitry Andric   for (const auto &Entry : Map) {
2980b57cec5SDimitry Andric     if (Entry.second.contains(Sym)) {
2990b57cec5SDimitry Andric       return Entry.first;
3000b57cec5SDimitry Andric     }
3010b57cec5SDimitry Andric   }
3020b57cec5SDimitry Andric   return nullptr;
3030b57cec5SDimitry Andric }
3040b57cec5SDimitry Andric 
3050b57cec5SDimitry Andric } // end namespace allocation_state
3060b57cec5SDimitry Andric } // end namespace ento
3070b57cec5SDimitry Andric } // end namespace clang
3080b57cec5SDimitry Andric 
309a7dea167SDimitry Andric PathDiagnosticPieceRef InnerPointerChecker::InnerPointerBRVisitor::VisitNode(
310a7dea167SDimitry Andric     const ExplodedNode *N, BugReporterContext &BRC, PathSensitiveBugReport &) {
3110b57cec5SDimitry Andric   if (!isSymbolTracked(N->getState(), PtrToBuf) ||
3120b57cec5SDimitry Andric       isSymbolTracked(N->getFirstPred()->getState(), PtrToBuf))
3130b57cec5SDimitry Andric     return nullptr;
3140b57cec5SDimitry Andric 
315a7dea167SDimitry Andric   const Stmt *S = N->getStmtForDiagnostics();
3160b57cec5SDimitry Andric   if (!S)
3170b57cec5SDimitry Andric     return nullptr;
3180b57cec5SDimitry Andric 
3190b57cec5SDimitry Andric   const MemRegion *ObjRegion =
3200b57cec5SDimitry Andric       allocation_state::getContainerObjRegion(N->getState(), PtrToBuf);
3210b57cec5SDimitry Andric   const auto *TypedRegion = cast<TypedValueRegion>(ObjRegion);
3220b57cec5SDimitry Andric   QualType ObjTy = TypedRegion->getValueType();
3230b57cec5SDimitry Andric 
3240b57cec5SDimitry Andric   SmallString<256> Buf;
3250b57cec5SDimitry Andric   llvm::raw_svector_ostream OS(Buf);
3260b57cec5SDimitry Andric   OS << "Pointer to inner buffer of '" << ObjTy.getAsString()
3270b57cec5SDimitry Andric      << "' obtained here";
3280b57cec5SDimitry Andric   PathDiagnosticLocation Pos(S, BRC.getSourceManager(),
3290b57cec5SDimitry Andric                              N->getLocationContext());
330a7dea167SDimitry Andric   return std::make_shared<PathDiagnosticEventPiece>(Pos, OS.str(), true);
3310b57cec5SDimitry Andric }
3320b57cec5SDimitry Andric 
3330b57cec5SDimitry Andric void ento::registerInnerPointerChecker(CheckerManager &Mgr) {
3340b57cec5SDimitry Andric   registerInnerPointerCheckerAux(Mgr);
3350b57cec5SDimitry Andric   Mgr.registerChecker<InnerPointerChecker>();
3360b57cec5SDimitry Andric }
3370b57cec5SDimitry Andric 
3385ffd83dbSDimitry Andric bool ento::shouldRegisterInnerPointerChecker(const CheckerManager &mgr) {
3390b57cec5SDimitry Andric   return true;
3400b57cec5SDimitry Andric }
341