clang 22.0.0git
RecordOps.h
Go to the documentation of this file.
1//===-- RecordOps.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// Operations on records (structs, classes, and unions).
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_RECORDOPS_H
14#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_RECORDOPS_H
15
16#include "clang/AST/Type.h"
19
20namespace clang {
21namespace dataflow {
22
23/// Copies a record (struct, class, or union) from `Src` to `Dst`.
24///
25/// This performs a deep copy, i.e. it copies every field (including synthetic
26/// fields) and recurses on fields of record type.
27///
28/// If there is a `RecordValue` associated with `Dst` in the environment, this
29/// function creates a new `RecordValue` and associates it with `Dst`; clients
30/// need to be aware of this and must not assume that the `RecordValue`
31/// associated with `Dst` remains the same after the call.
32///
33/// Requirements:
34///
35/// Either:
36/// - `Src` and `Dest` must have the same canonical unqualified type, or
37/// - The type of `Src` must be derived from `Dest`, or
38/// - The type of `Dest` must be derived from `Src` (in this case, any fields
39/// that are only present in `Dest` are not overwritten).
40/// - The types of `Dest` and `Src` are both derived from a non-null
41/// `TypeToCopy` (in this case, only fields present in `TypeToCopy` are
42/// overwritten).
44 Environment &Env, QualType TypeToCopy = QualType());
45
46/// Returns whether the records `Loc1` and `Loc2` are equal.
47///
48/// Values for `Loc1` are retrieved from `Env1`, and values for `Loc2` are
49/// retrieved from `Env2`. A convenience overload retrieves values for `Loc1`
50/// and `Loc2` from the same environment.
51///
52/// This performs a deep comparison, i.e. it compares every field (including
53/// synthetic fields) and recurses on fields of record type. Fields of reference
54/// type compare equal if they refer to the same storage location.
55///
56/// Note on how to interpret the result:
57/// - If this returns true, the records are guaranteed to be equal at runtime.
58/// - If this returns false, the records may still be equal at runtime; our
59/// analysis merely cannot guarantee that they will be equal.
60///
61/// Requirements:
62///
63/// `Src` and `Dst` must have the same canonical unqualified type.
64bool recordsEqual(const RecordStorageLocation &Loc1, const Environment &Env1,
65 const RecordStorageLocation &Loc2, const Environment &Env2);
66
67inline bool recordsEqual(const RecordStorageLocation &Loc1,
68 const RecordStorageLocation &Loc2,
69 const Environment &Env) {
70 return recordsEqual(Loc1, Env, Loc2, Env);
71}
72
73} // namespace dataflow
74} // namespace clang
75
76#endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_RECORDOPS_H
C Language Family Type Representation.
Holds the state of the program (store and heap) at a given program point.
A storage location for a record (struct, class, or union).
Dataflow Directional Tag Classes.
Definition AdornedCFG.h:29
void copyRecord(RecordStorageLocation &Src, RecordStorageLocation &Dst, Environment &Env, QualType TypeToCopy=QualType())
Copies a record (struct, class, or union) from Src to Dst.
Definition RecordOps.cpp:54
bool recordsEqual(const RecordStorageLocation &Loc1, const Environment &Env1, const RecordStorageLocation &Loc2, const Environment &Env2)
Returns whether the records Loc1 and Loc2 are equal.
The JSON file list parser is used to communicate input to InstallAPI.