[compiler-rt] [profile] Perform pointer arithmetic in uintptr_t (PR #118944)

Ellis Hoag via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 6 12:40:56 PST 2024


================
@@ -143,49 +137,46 @@ int __llvm_profile_merge_from_buffer(const char *ProfileData,
     return 1;
   }
 
-  __llvm_profile_data *SrcDataStart, *SrcDataEnd, *SrcData, *DstData;
   __llvm_profile_header *Header = (__llvm_profile_header *)ProfileData;
-  char *SrcCountersStart, *DstCounter;
-  const char *SrcCountersEnd, *SrcCounter;
-  const char *SrcBitmapStart;
-  const char *SrcNameStart;
-  const char *SrcValueProfDataStart, *SrcValueProfData;
   uintptr_t CountersDelta = Header->CountersDelta;
   uintptr_t BitmapDelta = Header->BitmapDelta;
 
-  SrcDataStart =
+  __llvm_profile_data *SrcDataStart =
       (__llvm_profile_data *)(ProfileData + sizeof(__llvm_profile_header) +
                               Header->BinaryIdsSize);
-  SrcDataEnd = SrcDataStart + Header->NumData;
-  SrcCountersStart = (char *)SrcDataEnd;
-  SrcCountersEnd = SrcCountersStart +
-                   Header->NumCounters * __llvm_profile_counter_entry_size();
-  SrcBitmapStart = ptr_add_with_overflow(
-      SrcCountersEnd,
-      __llvm_profile_get_num_padding_bytes(SrcCountersEnd - SrcCountersStart));
-  SrcNameStart = ptr_add_with_overflow(SrcBitmapStart, Header->NumBitmapBytes);
-  SrcValueProfDataStart =
+  __llvm_profile_data *SrcDataEnd = SrcDataStart + Header->NumData;
+  uintptr_t SrcCountersStart = (uintptr_t)SrcDataEnd;
----------------
ellishg wrote:

I don't think we need the explicit cast, do we? Same for `DstCounter` on line 165.

```suggestion
  uintptr_t SrcCountersStart = SrcDataEnd;
```

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


More information about the llvm-commits mailing list