[clang-tools-extra] [llvm] [compiler-rt] [clang] [IRPGO][ValueProfile] Instrument virtual table address that could be used to do virtual table address comparision for indirect-call-promotion. (PR #66825)

Snehasish Kumar via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 8 11:47:38 PST 2023


================
@@ -1441,6 +1531,9 @@ void OverlapStats::dump(raw_fd_ostream &OS) const {
     case IPVK_MemOPSize:
       strncpy(ProfileKindName, "MemOP", 19);
       break;
+    case IPVK_VTableTarget:
+      strncpy(ProfileKindName, "VTable", 6);
----------------
snehasish wrote:

I think this usage of strncpy is incorrect. It will not copy the null terminator from the "VTable" const char * since the null terminator is the 7th char. Since ProfileKindName is uninitialized it could lead to issues when reading it.

The existing code should initialize `ProfileKindName[20] = {0}` and then the value of 19 used above makes sense. It will attempt to copy 19 chars unless it encounters the null char in which case the rest will be padded. What do you think?

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


More information about the cfe-commits mailing list