misc: Merge branch 'release-staging-v20.0.0.0' into develop
[gem5.git] / src / dev / hsa / hw_scheduler.cc
index 6b371551bd9d330e398cb374808044ceedc0b0c5..57cf6d1b189b52fcd39a63c9f528fb015b771420 100644 (file)
@@ -90,7 +90,12 @@ HWScheduler::registerNewQueue(uint64_t hostReadIndexPointer,
     // Map queue ID to doorbell.
     // We are only using offset to pio base address as doorbell
     // We use the same mapping function used by hsa runtime to do this mapping
-    Addr db_offset = (Addr)(VOID_PTR_ADD32(0, queue_id));
+    //
+    // Originally
+    // #define VOID_PTR_ADD32(ptr,n) \
+    //     (void*)((uint32_t*)(ptr) + n)/*ptr + offset*/
+    // (Addr)VOID_PTR_ADD32(0, queue_id)
+    Addr db_offset = queue_id;
     if (dbMap.find(db_offset) != dbMap.end()) {
         panic("Creating an already existing queue (queueID %d)", queue_id);
     }
@@ -333,7 +338,15 @@ HWScheduler::write(Addr db_addr, uint32_t doorbell_reg)
 void
 HWScheduler::unregisterQueue(uint64_t queue_id)
 {
-    Addr db_offset = (Addr)(VOID_PTR_ADD32(0, queue_id));
+    // Pointer arithmetic on a null pointer is undefined behavior. Clang
+    // compilers therefore complain if the following reads:
+    // `(Addr)(VOID_PRT_ADD32(0, queue_id))`
+    //
+    // Originally
+    // #define VOID_PTR_ADD32(ptr,n) \
+    //     (void*)((uint32_t*)(ptr) + n)/*ptr + offset*/
+    // (Addr)VOID_PTR_ADD32(0, queue_id)
+    Addr db_offset = queue_id;
     auto dbmap_iter = dbMap.find(db_offset);
     if (dbmap_iter == dbMap.end()) {
         panic("Destroying a non-existing queue (db_offset %x)",