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/Analysis/FlowSensitive/DataflowEnvironment.h" 17 #include "clang/Analysis/FlowSensitive/StorageLocation.h" 18 19 namespace clang { 20 namespace dataflow { 21 22 /// Copies a record (struct, class, or union) from `Src` to `Dst`. 23 /// 24 /// This performs a deep copy, i.e. it copies every field (including synthetic 25 /// fields) and recurses on fields of record type. 26 /// 27 /// If there is a `RecordValue` associated with `Dst` in the environment, this 28 /// function creates a new `RecordValue` and associates it with `Dst`; clients 29 /// need to be aware of this and must not assume that the `RecordValue` 30 /// associated with `Dst` remains the same after the call. 31 /// 32 /// Requirements: 33 /// 34 /// `Src` and `Dst` must have the same canonical unqualified type. 35 void copyRecord(RecordStorageLocation &Src, RecordStorageLocation &Dst, 36 Environment &Env); 37 38 /// Returns whether the records `Loc1` and `Loc2` are equal. 39 /// 40 /// Values for `Loc1` are retrieved from `Env1`, and values for `Loc2` are 41 /// retrieved from `Env2`. A convenience overload retrieves values for `Loc1` 42 /// and `Loc2` from the same environment. 43 /// 44 /// This performs a deep comparison, i.e. it compares every field (including 45 /// synthetic fields) and recurses on fields of record type. Fields of reference 46 /// type compare equal if they refer to the same storage location. 47 /// 48 /// Note on how to interpret the result: 49 /// - If this returns true, the records are guaranteed to be equal at runtime. 50 /// - If this returns false, the records may still be equal at runtime; our 51 /// analysis merely cannot guarantee that they will be equal. 52 /// 53 /// Requirements: 54 /// 55 /// `Src` and `Dst` must have the same canonical unqualified type. 56 bool recordsEqual(const RecordStorageLocation &Loc1, const Environment &Env1, 57 const RecordStorageLocation &Loc2, const Environment &Env2); 58 59 inline bool recordsEqual(const RecordStorageLocation &Loc1, 60 const RecordStorageLocation &Loc2, 61 const Environment &Env) { 62 return recordsEqual(Loc1, Env, Loc2, Env); 63 } 64 65 } // namespace dataflow 66 } // namespace clang 67 68 #endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_RECORDOPS_H 69