[clang] [clang][dataflow] Expose getReferencedDecls and relocate free functions. (PR #88754)

via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 16 00:16:12 PDT 2024


================
@@ -66,6 +66,35 @@ inline bool recordsEqual(const RecordStorageLocation &Loc1,
   return recordsEqual(Loc1, Env, Loc2, Env);
 }
 
+/// Helper class for initialization of a record with an `InitListExpr`.
+/// `InitListExpr::inits()` contains the initializers for both the base classes
+/// and the fields of the record; this helper class separates these out into two
+/// different lists. In addition, it deals with special cases associated with
+/// unions.
+class RecordInitListHelper {
+public:
+  // `InitList` must have record type.
+  RecordInitListHelper(const InitListExpr *InitList);
+
+  // Base classes with their associated initializer expressions.
+  ArrayRef<std::pair<const CXXBaseSpecifier *, Expr *>> base_inits() const {
+    return BaseInits;
+  }
+
+  // Fields with their associated initializer expressions.
+  ArrayRef<std::pair<const FieldDecl *, Expr *>> field_inits() const {
+    return FieldInits;
+  }
+
+private:
+  SmallVector<std::pair<const CXXBaseSpecifier *, Expr *>> BaseInits;
+  SmallVector<std::pair<const FieldDecl *, Expr *>> FieldInits;
+
+  // We potentially synthesize an `ImplicitValueInitExpr` for unions. It's a
+  // member variable because we store a pointer to it in `FieldInits`.
+  std::optional<ImplicitValueInitExpr> ImplicitValueInitForUnion;
+};
+
----------------
martinboehme wrote:

I think this would fit better in ASTOps.h as well.

The intent of RecordOps.h is to contain functions that operate on our representation of record objects, i.e. `RecordStorageLocation`s. `RecordInitListHelper`, on the other hand, is just a more convenient way of accessing the initializers in an `InitListExpr` and so seems a better fit in ASTOps.h. (Note also that the closely related `getFieldsForInitListExpr()` already lives there.)

https://github.com/llvm/llvm-project/pull/88754


More information about the cfe-commits mailing list