[clang] [llvm] [mlir] [TableGen] Change `DefInit::Def` to a const Record pointer (PR #110747)

Rahul Joshi via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 2 08:29:00 PDT 2024


================
@@ -1660,7 +1660,7 @@ class Record {
   // this record.
   SmallVector<SMLoc, 4> Locs;
   SmallVector<SMLoc, 0> ForwardDeclarationLocs;
-  SmallVector<SMRange, 0> ReferenceLocs;
+  mutable SmallVector<SMRange, 0> ReferenceLocs;
----------------
jurahul wrote:

This was needed in `ParseIDValue`:

```
  if (Init *I = Records.getGlobal(Name->getValue())) {
    // Add a reference to the global if it's a record.
    if (TrackReferenceLocs) {
      if (auto *Def = dyn_cast<DefInit>(I)) 
        const_cast<Record *>(Def->getDef())->appendReferenceLoc(NameLoc);
    }
    return I;
  }

Def->getDef() is not a const pointer. I can change the code to what is shown above and make the function non-const.

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


More information about the cfe-commits mailing list