[clang] [clang] Fix a dangling reference in clang/utils/TableGen/ClangDiagnosticsEmitter.cpp (PR #119197)

Rahul Joshi via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 10 11:06:14 PST 2024


================
@@ -1908,7 +1908,7 @@ void clang::EmitClangDiagDocs(const RecordKeeper &Records, raw_ostream &OS) {
   for (const Record *G : DiagGroups) {
     bool IsRemarkGroup = isRemarkGroup(G, DiagsInGroup);
     auto &GroupInfo =
-        DiagsInGroup[std::string(G->getValueAsString("GroupName"))];
----------------
jurahul wrote:

Yeah, we need to document it. I can see from the code that we iterate over the map (in emitDiagTable)

```
  for (auto const &[Name, GroupInfo] : DiagsInGroup) {
```

with std::map, this iteration happens in an order sorted by the keys in the map. And that is needed so that the tablegen generated code is deterministic. I don't think StringMap similar iteration order guarantees. See https://llvm.org/docs/ProgrammersManual.html#llvm-adt-stringmap-h

```
StringMap iteration order, however, is not guaranteed to be deterministic, so any uses which require that should instead use a std::map.
```


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


More information about the cfe-commits mailing list