Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:25

0001 //===-- RecordOps.h ---------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 //  Operations on records (structs, classes, and unions).
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_RECORDOPS_H
0014 #define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_RECORDOPS_H
0015 
0016 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
0017 #include "clang/Analysis/FlowSensitive/StorageLocation.h"
0018 
0019 namespace clang {
0020 namespace dataflow {
0021 
0022 /// Copies a record (struct, class, or union) from `Src` to `Dst`.
0023 ///
0024 /// This performs a deep copy, i.e. it copies every field (including synthetic
0025 /// fields) and recurses on fields of record type.
0026 ///
0027 /// If there is a `RecordValue` associated with `Dst` in the environment, this
0028 /// function creates a new `RecordValue` and associates it with `Dst`; clients
0029 /// need to be aware of this and must not assume that the `RecordValue`
0030 /// associated with `Dst` remains the same after the call.
0031 ///
0032 /// Requirements:
0033 ///
0034 ///  Either:
0035 ///    - `Src` and `Dest` must have the same canonical unqualified type, or
0036 ///    - The type of `Src` must be derived from `Dest`, or
0037 ///    - The type of `Dest` must be derived from `Src` (in this case, any fields
0038 ///      that are only present in `Dest` are not overwritten).
0039 void copyRecord(RecordStorageLocation &Src, RecordStorageLocation &Dst,
0040                 Environment &Env);
0041 
0042 /// Returns whether the records `Loc1` and `Loc2` are equal.
0043 ///
0044 /// Values for `Loc1` are retrieved from `Env1`, and values for `Loc2` are
0045 /// retrieved from `Env2`. A convenience overload retrieves values for `Loc1`
0046 /// and `Loc2` from the same environment.
0047 ///
0048 /// This performs a deep comparison, i.e. it compares every field (including
0049 /// synthetic fields) and recurses on fields of record type. Fields of reference
0050 /// type compare equal if they refer to the same storage location.
0051 ///
0052 /// Note on how to interpret the result:
0053 /// - If this returns true, the records are guaranteed to be equal at runtime.
0054 /// - If this returns false, the records may still be equal at runtime; our
0055 ///   analysis merely cannot guarantee that they will be equal.
0056 ///
0057 /// Requirements:
0058 ///
0059 ///  `Src` and `Dst` must have the same canonical unqualified type.
0060 bool recordsEqual(const RecordStorageLocation &Loc1, const Environment &Env1,
0061                   const RecordStorageLocation &Loc2, const Environment &Env2);
0062 
0063 inline bool recordsEqual(const RecordStorageLocation &Loc1,
0064                          const RecordStorageLocation &Loc2,
0065                          const Environment &Env) {
0066   return recordsEqual(Loc1, Env, Loc2, Env);
0067 }
0068 
0069 } // namespace dataflow
0070 } // namespace clang
0071 
0072 #endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_RECORDOPS_H