[clang] [clang][dataflow] Correctly handle `InitListExpr` of union type. (PR #82348)

via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 21 00:10:44 PST 2024


================
@@ -1104,12 +1104,22 @@ RecordStorageLocation *getBaseObjectLocation(const MemberExpr &ME,
   return Env.get<RecordStorageLocation>(*Base);
 }
 
-std::vector<FieldDecl *> getFieldsForInitListExpr(const RecordDecl *RD) {
+std::vector<const FieldDecl *>
+getFieldsForInitListExpr(const InitListExpr *InitList) {
+  const RecordDecl *RD = InitList->getType()->getAsRecordDecl();
+  assert(RD != nullptr);
+
+  std::vector<const FieldDecl *> Fields;
----------------
martinboehme wrote:

Makes sense. Unfortunately, `RecordDecl` doesn't have a way (that I know of) to query the number of fields. There's no `getNumFields()` or similar, and `field_end()-field_begin()` also doesn't work (because the iterator doesn't support `operator-`. So we'd have to do a complete iteration through the fields to determine the number, and at that point, I think we're getting into diminishing returns.

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


More information about the cfe-commits mailing list