[PATCH] D17407: [Sema] PR25755 Fix crash when initializing out-of-order struct references

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 18 10:49:26 PDT 2016


rsmith added inline comments.

================
Comment at: lib/Sema/SemaInit.cpp:1732
@@ +1731,3 @@
+  unsigned FieldIdx = 0;
+  std::vector<unsigned> SeenFields;
+  RecordDecl::field_iterator FieldStart = Field;
----------------
Please use an `llvm::BitVector` here instead.

================
Comment at: lib/Sema/SemaInit.cpp:1756-1769
@@ -1752,2 +1755,16 @@
 
+      if (CheckForMissingFields)
+        for (unsigned i = 0; i < FieldIdx; ++i)
+          SeenFields.push_back(i);
+      unsigned idx = 0;
+      for (RecordDecl::field_iterator f = FieldStart;
+           f != FieldEnd; ++idx, ++f) {
+        auto Next = f;
+        if (++Next == Field) {
+          FieldIdx = idx;
+          break;
+        }
+      }
+      SeenFields.push_back(FieldIdx);
+      ++FieldIdx;
       InitializedSomething = true;
----------------
You can get the field index with `Field->getFieldIndex() - 1` rather than computing it here (though watch out for the case where `Field == FieldEnd`).

================
Comment at: lib/Sema/SemaInit.cpp:1793-1795
@@ -1775,2 +1792,5 @@
       // Don't initialize unnamed bitfields, e.g. "int : 20;"
+      if (!CheckForMissingFields)
+        SeenFields.push_back(FieldIdx);
+      ++FieldIdx;
       ++Field;
----------------
We don't need to track whether unnamed bit-fields have been "seen". This isn't meaningful.

================
Comment at: lib/Sema/SemaInit.cpp:1808-1809
@@ -1787,1 +1807,4 @@
     if (InvalidUse) {
+      if (!CheckForMissingFields)
+        SeenFields.push_back(FieldIdx);
+      ++FieldIdx;
----------------
Once we're in the `hadError` state, we don't need to track `SeenFields` any more. I don't think we need this change.


http://reviews.llvm.org/D17407





More information about the cfe-commits mailing list