[clang] [llvm] [TableGen] Change SetTheory set/vec to use const Record * (PR #107692)

Rahul Joshi via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 8 10:40:21 PDT 2024


================
@@ -2808,10 +2806,10 @@ RecordRecTy *Record::getType() {
   return RecordRecTy::get(TrackedRecords, DirectSCs);
 }
 
-DefInit *Record::getDefInit() {
+DefInit *Record::getDefInit() const {
   if (!CorrespondingDefInit) {
-    CorrespondingDefInit =
-        new (TrackedRecords.getImpl().Allocator) DefInit(this);
+    CorrespondingDefInit = new (TrackedRecords.getImpl().Allocator)
+        DefInit(const_cast<Record *>(this));
----------------
jurahul wrote:

The only issue/smell is here, where CodeGenDAGPatterns.cpp and CodeGenRegisters.cpp call DefInit::get() on the result of a SetTheory::expand() returned record (which is now const *). I looked a little bit to see what they are doing, but decided to "cut off" the change here to keep it smaller. This is part of effort to have better const correctness w.r.t records and recordkeeper, so with this, the "smell" is atleast localized to this function and we can have const records otherwise.

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


More information about the cfe-commits mailing list