| Issue |
176454
|
| Summary |
`-Wassign-enum` performance degrades significantly for enums with many enumerators
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
ahatanak
|
When compiling code that triggers `-Wassign-enum` on an enum with a large number of enumerators, compilation becomes noticeably slow. You can reproduce this by running the attached Python script, which generates a large enum and assigns integer values to it.
The slowdown appears to come from `Sema::DiagnoseAssignmentEnum`. The function sorts the list of enumerators on every invocation and then performs a linear scan to determine whether the assigned value is in range.
```
llvm::stable_sort(EnumVals, CmpEnumVals);
EnumValsTy::iterator EIend = llvm::unique(EnumVals, EqEnumVals);
// See which values aren't in the enum.
EnumValsTy::const_iterator EI = EnumVals.begin();
while (EI != EIend && EI->first < *RHSVal)
EI++;
if (EI == EIend || EI->first != *RHSVal) {
Diag(SrcExpr->getExprLoc(), diag::warn_not_in_enum_assignment)
<< DstType.getUnqualifiedType();
}
```
[gen_clang_test.py](https://github.com/user-attachments/files/24680172/gen_clang_test.py)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs