Skip to content

Commit c310a45

Browse files
committed
check null ptr returned by aligned_alloc
Signed-off-by: jinge90 <[email protected]>
1 parent 094bcfc commit c310a45

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

llvm/lib/SYCLLowerIR/ComputeModuleRuntimeInfo.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,22 @@ PropSetRegTy computeModuleProperties(const Module &M,
193193
uint8_t *SPVBuffer = reinterpret_cast<uint8_t *>(
194194
std::aligned_alloc(alignof(uint32_t), SPVSize + sizeof(uint32_t)));
195195
#endif
196+
197+
if (!SPVBuffer)
198+
continue;
199+
200+
// The data embedded consists of 2 parts, first 4 bytes are corresponding
201+
// DeivceLib extension and the following bytes are raw data of fallback
202+
// spv files. There is 1 exception for native bfloat16 spv, it is used
203+
// to support native bfloat16 conversions on some devices and it doesn't
204+
// fully comply to fallback device library mechanism, the extension
205+
// 'cl_intel_devicelib_bfloat16' corresponds to 2 fallback spvs: native
206+
// version used for devices which supports native bfloat16 conversion and
207+
// generic version for all other devices, so we have to embed 1 one field
208+
// to distinguish.
196209
*(reinterpret_cast<uint32_t *>(SPVBuffer)) = static_cast<uint32_t>(Ext);
197-
std::memcpy(SPVBuffer + sizeof(uint32_t), (*SPVMB)->getBufferStart(),
210+
size_t RawSPVOffset = sizeof(uint32_t);
211+
std::memcpy(SPVBuffer + RawSPVOffset, (*SPVMB)->getBufferStart(),
198212
SPVSize);
199213
llvm::SYCLDeviceLibSPVBinary SPVBinaryObj(SPVBuffer,
200214
SPVSize + sizeof(uint32_t));

0 commit comments

Comments
 (0)