[clang] [llvm] [mlir] [LLVM][TableGen] Change SeachableTableEmitter to use const RecordKeeper (PR #110032)

Rahul Joshi via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 30 06:54:51 PDT 2024


================
@@ -1556,7 +1557,7 @@ class RecordVal {
   bool IsUsed = false;
 
   /// Reference locations to this record value.
-  SmallVector<SMRange> ReferenceLocs;
+  mutable SmallVector<SMRange> ReferenceLocs;
----------------
jurahul wrote:

This was needed because the Record * pointers in `RecordRecTy::getClasses` are now const, so this code in TGParser.cpp does not work:

```
      // Add a reference to this field if we know the record class.
      if (TrackReferenceLocs) {
        if (auto *DI = dyn_cast<DefInit>(Result)) {
          DI->getDef()->getValue(FieldName)->addReferenceLoc(FieldNameLoc);
        } else if (auto *TI = dyn_cast<TypedInit>(Result)) {
          if (auto *RecTy = dyn_cast<RecordRecTy>(TI->getType())) {
            for (const Record *R : RecTy->getClasses())
              if (auto *RV = R->getValue(FieldName))
                RV->addReferenceLoc(FieldNameLoc);
          }
        }
      }
```

However, may be its better to localize the const_cast here as opposed to making the member mutable since its just that one place. I'll do that

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


More information about the cfe-commits mailing list