Index: lib/profile/InstrProfilingWriter.c =================================================================== --- lib/profile/InstrProfilingWriter.c +++ lib/profile/InstrProfilingWriter.c @@ -91,6 +91,15 @@ return 0; } +static int hasNoValueSites(const __llvm_profile_data *DataBegin, + const __llvm_profile_data *DataEnd) { + for (; DataBegin != DataEnd; ++DataBegin) + for (int I = 0; I <= IPVK_Last; I++) + if (DataBegin->NumValueSites[I] != 0) + return 0; + return 1; +} + #define VP_BUFFER_SIZE 8 * 1024 static int writeValueProfData(WriterCallback Writer, void *WriterCtx, VPGatherHookType VPDataGatherer, @@ -100,7 +109,10 @@ uint32_t BufferSz; const __llvm_profile_data *DI = 0; - if (!VPDataGatherer) + /* Bail out early so that we don't attempt to call any memory allocation + * functions. + */ + if (!VPDataGatherer || hasNoValueSites(DataBegin, DataEnd)) return 0; BufferSz = VPBufferSize ? VPBufferSize : VP_BUFFER_SIZE;