gemini-code-assist[bot] commented on code in PR #19605:
URL: https://github.com/apache/tvm/pull/19605#discussion_r3303585799


##########
src/s_tir/transform/merge_shared_memory_allocations.cc:
##########
@@ -611,16 +711,16 @@ class SharedMemoryRewriter : public StmtExprMutator {
 
     if (const_nbits != 0) {
       // constant allocation.
-      auto begin = const_free_map_.lower_bound(0);
-      auto mid = const_free_map_.lower_bound(const_nbits);
-      auto end = const_free_map_.upper_bound(const_nbits * match_range);
+      auto begin = scope.const_free_map.lower_bound(0);
+      auto mid = scope.const_free_map.lower_bound(const_nbits);
+      auto end = scope.const_free_map.upper_bound(const_nbits * match_range);
       // Start looking at the buffer that is bigger than the required size 
first.
       // If we find one, directly allocate the buffer in its location and 
remove its entry in the
       // free list
       for (auto it = mid; it != end; ++it) {
         StorageEntry* e = it->second;
         e->const_nbits = std::max(const_nbits, e->const_nbits);
-        const_free_map_.erase(it);
+        scope.const_free_map.erase(it);
         it->second->allocs.push_back({buf->data.get()});
         return e;
       }

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   Accessing `it->second` after erasing `it` from `scope.const_free_map` is 
undefined behavior because the iterator `it` is invalidated by the `erase` 
call. Since `e` already holds `it->second`, you should use `e->allocs` directly.
   
   ```suggestion
         for (auto it = mid; it != end; ++it) {
           StorageEntry* e = it->second;
           e->const_nbits = std::max(const_nbits, e->const_nbits);
           scope.const_free_map.erase(it);
           e->allocs.push_back({buf->data.get()});
           return e;
         }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to