clang 20.0.0git
CachedConstAccessorsLattice.h
Go to the documentation of this file.
1//===-- CachedConstAccessorsLattice.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 the lattice mixin that additionally maintains a cache of
10// stable method call return values to model const accessor member functions.
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CACHED_CONST_ACCESSORS_LATTICE_H
14#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CACHED_CONST_ACCESSORS_LATTICE_H
15
16#include "clang/AST/Decl.h"
17#include "clang/AST/Expr.h"
18#include "clang/AST/Type.h"
23#include "llvm/ADT/DenseMap.h"
24#include "llvm/ADT/STLFunctionalExtras.h"
25
26namespace clang {
27namespace dataflow {
28
29/// A mixin for a lattice that additionally maintains a cache of stable method
30/// call return values to model const accessors methods. When a non-const method
31/// is called, the cache should be cleared causing the next call to a const
32/// method to be considered a different value. NOTE: The user is responsible for
33/// clearing the cache.
34///
35/// For example:
36///
37/// class Bar {
38/// public:
39/// const std::optional<Foo>& getFoo() const;
40/// void clear();
41/// };
42//
43/// void func(Bar& s) {
44/// if (s.getFoo().has_value()) {
45/// use(s.getFoo().value()); // safe (checked earlier getFoo())
46/// s.clear();
47/// use(s.getFoo().value()); // unsafe (invalidate cache for s)
48/// }
49/// }