[compiler-rt] 317e00d - [PGO] Change a `NumVSites == 0` workaround to assert

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 3 10:14:11 PDT 2020


Author: Fangrui Song
Date: 2020-08-03T10:14:03-07:00
New Revision: 317e00dc54c74a2e0fd0c62bdc6a6d68b0d2ca7e

URL: https://github.com/llvm/llvm-project/commit/317e00dc54c74a2e0fd0c62bdc6a6d68b0d2ca7e
DIFF: https://github.com/llvm/llvm-project/commit/317e00dc54c74a2e0fd0c62bdc6a6d68b0d2ca7e.diff

LOG: [PGO] Change a `NumVSites == 0` workaround to assert

The root cause was fixed by 3d6f53018f845e893ad34f64ff2851a2e5c3ba1d.
The workaround added in 99ad956fdaee5398fdcf46fa49cb433cf52dc461 can be changed
to an assert now. (In case the fix regresses, there will be a heap-use-after-free.)

Added: 
    

Modified: 
    compiler-rt/lib/profile/InstrProfilingValue.c

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/profile/InstrProfilingValue.c b/compiler-rt/lib/profile/InstrProfilingValue.c
index 29b9e628a9c9..4b4081bd21b7 100644
--- a/compiler-rt/lib/profile/InstrProfilingValue.c
+++ b/compiler-rt/lib/profile/InstrProfilingValue.c
@@ -6,6 +6,7 @@
 |*
 \*===----------------------------------------------------------------------===*/
 
+#include <assert.h>
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -93,8 +94,8 @@ static int allocateValueProfileCounters(__llvm_profile_data *Data) {
   for (VKI = IPVK_First; VKI <= IPVK_Last; ++VKI)
     NumVSites += Data->NumValueSites[VKI];
 
-  if (NumVSites == 0)
-    return 0;
+  // If NumVSites = 0, calloc is allowed to return a non-null pointer.
+  assert(NumVSites > 0 && "NumVSites can't be zero");
   ValueProfNode **Mem =
       (ValueProfNode **)calloc(NumVSites, sizeof(ValueProfNode *));
   if (!Mem)


        


More information about the llvm-commits mailing list