clang 20.0.0git
SmartPointerAccessorCaching.h
Go to the documentation of this file.
1//===-- SmartPointerAccessorCaching.h ---------------------------*- C++ -*-===//
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// This file defines utilities to help cache accessors for smart pointer
10// like objects.
11//
12// These should be combined with CachedConstAccessorsLattice.
13// Beyond basic const accessors, smart pointers may have the following two
14// additional issues:
15//
16// 1) There may be multiple accessors for the same underlying object, e.g.
17// `operator->`, `operator*`, and `get`. Users may use a mixture of these
18// accessors, so the cache should unify them.
19//
20// 2) There may be non-const overloads of accessors. They are still safe to
21// cache, as they don't modify the container object.
22//===----------------------------------------------------------------------===//
23
24#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_SMARTPOINTERACCESSORCACHING_H
25#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_SMARTPOINTERACCESSORCACHING_H
26
27#include <cassert>
28
29#include "clang/AST/Decl.h"
30#include "clang/AST/Stmt.h"
32
33namespace clang::dataflow {
34
35/// Matchers:
36/// For now, these match on any class with an `operator*` or `operator->`
37/// where the return types have a similar shape as std::unique_ptr
38/// and std::optional.
39///
40/// - `*` returns a reference to a type `T`
41/// - `->` returns a pointer to `T`
42/// - `get` returns a pointer to `T`
43/// - `value` returns a reference `T`
44///
45/// (1) The `T` should all match across the accessors (ignoring qualifiers).
46///
47/// (2) The specific accessor used in a call isn't required to be const,
48/// but the class must have a const overload of each accessor.
49///
50/// For now, we don't have customization to ignore certain classes.
51/// For example, if writing a ClangTidy check for `std::optional`, these
52/// would also match `std::optional`. In order to have special handling
53/// for `std::optional`, we assume the (Matcher, TransferFunction) case
54/// with custom handling is ordered early so that these generic cases
55/// do not trigger.
60
61} // namespace clang::dataflow
62
63#endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_SMARTPOINTERACCESSORCACHING_H
internal::Matcher< Stmt > StatementMatcher
Definition: ASTMatchers.h:144
Dataflow Directional Tag Classes.
Definition: AdornedCFG.h:29
ast_matchers::StatementMatcher isSmartPointerLikeGetMethodCall()
ast_matchers::StatementMatcher isSmartPointerLikeValueMethodCall()
ast_matchers::StatementMatcher isSmartPointerLikeOperatorArrow()
ast_matchers::StatementMatcher isSmartPointerLikeOperatorStar()
Matchers: For now, these match on any class with an operator* or operator-> where the return types ha...