Skip to content

Commit 99ad956

Browse files
committed
[PGO] Don't call calloc(0, sizeof(ValueProfNode *))
A malloc implementation may return a pointer to some allocated space. It is undefined for libclang_rt.profile- to access the object - which actually happens in instrumentTargetValueImpl, where ValueCounters[CounterIndex] may access a ValueProfNode (from another allocated object) and crashes when the code accesses the object referenced by CurVNode->Next.
1 parent 9e4ab43 commit 99ad956

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

compiler-rt/lib/profile/InstrProfilingValue.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ static int allocateValueProfileCounters(__llvm_profile_data *Data) {
9393
for (VKI = IPVK_First; VKI <= IPVK_Last; ++VKI)
9494
NumVSites += Data->NumValueSites[VKI];
9595

96+
if (NumVSites == 0)
97+
return 0;
9698
ValueProfNode **Mem =
9799
(ValueProfNode **)calloc(NumVSites, sizeof(ValueProfNode *));
98100
if (!Mem)

0 commit comments

Comments
 (0)