Skip to content

Commit 3fe916a

Browse files
authored
[SYCL] [NATIVECPU] Check null pointer after dyn cast (#11930)
1 parent 613d283 commit 3fe916a

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

llvm/lib/SYCLLowerIR/PrepareSYCLNativeCPU.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ static Function *addReplaceFunc(Module &M, StringRef Name, Type *StateType) {
295295
Type *PtrTy = PointerType::get(Ctx, NativeCPUGlobalAS);
296296
static FunctionType *FTy = FunctionType::get(RetTy, {DimTy, PtrTy}, false);
297297
auto FCallee = M.getOrInsertFunction(Name, FTy);
298-
auto *F = dyn_cast<Function>(FCallee.getCallee());
298+
auto *F = cast<Function>(FCallee.getCallee());
299299
IRBuilder<> Builder(Ctx);
300300
BasicBlock *BB = BasicBlock::Create(Ctx, "entry", F);
301301
Builder.SetInsertPoint(BB);
@@ -366,9 +366,7 @@ PreservedAnalyses PrepareSYCLNativeCPUPass::run(Module &M,
366366
if (!Glob)
367367
continue;
368368
for (const auto &Use : Glob->uses()) {
369-
auto I = dyn_cast<CallInst>(Use.getUser());
370-
if (!I)
371-
report_fatal_error("Unsupported Value in SYCL Native CPU\n");
369+
auto *I = cast<CallInst>(Use.getUser());
372370
if (!IsNativeCPUKernel(I->getFunction())) {
373371
// only use the threadlocal if we have kernels calling builtins
374372
// indirectly
@@ -417,9 +415,7 @@ PreservedAnalyses PrepareSYCLNativeCPUPass::run(Module &M,
417415
Function *const Glob = Entry.first;
418416
for (const auto &Use : Glob->uses()) {
419417
auto *ReplaceFunc = getReplaceFunc(M, Entry.second.first, StateType);
420-
auto I = dyn_cast<CallInst>(Use.getUser());
421-
if (!I)
422-
report_fatal_error("Unsupported Value in SYCL Native CPU\n");
418+
auto *I = cast<CallInst>(Use.getUser());
423419
auto *Arg = ConstantInt::get(Type::getInt32Ty(M.getContext()),
424420
Entry.second.second);
425421
auto *NewI = CallInst::Create(

0 commit comments

Comments
 (0)