================
@@ -1761,30 +1761,35 @@ Sema::DiagnoseAssignmentEnum(QualType DstType, QualType 
SrcType,
     return;
   }
 
-  typedef SmallVector<std::pair<llvm::APSInt, EnumConstantDecl *>, 64>
-      EnumValsTy;
-  EnumValsTy EnumVals;
-
-  // Gather all enum values, set their type and sort them,
-  // allowing easier comparison with rhs constant.
-  for (auto *EDI : ED->enumerators()) {
-    llvm::APSInt Val = EDI->getInitVal();
-    AdjustAPSInt(Val, DstWidth, DstIsSigned);
-    EnumVals.emplace_back(Val, EDI);
+  auto EnumValuesCmp = [](const llvm::APSInt &A, const llvm::APSInt &B) {
+    return A < B;
+  };
+
+  const EnumDecl *Key = ED->getCanonicalDecl();
+  auto [It, Inserted] = AssignEnumCache.try_emplace(Key);
+  auto &Values = It->second;
+
+  if (Inserted) {
+    Values.reserve(std::distance(ED->enumerator_begin(), 
ED->enumerator_end()));
+
+    for (auto *EC : ED->enumerators()) {
+      llvm::APSInt V = EC->getInitVal();
+      AdjustAPSInt(V, DstWidth, DstIsSigned);
+      Values.push_back(V);
----------------
Sirraide wrote:

That should also work, yeah

https://github.com/llvm/llvm-project/pull/176560
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to