Skip to content

Commit

Permalink
[SYCL] [NATIVECPU] Check null pointer after dyn cast (#11930)
Browse files Browse the repository at this point in the history
  • Loading branch information
PietroGhg authored Nov 21, 2023
1 parent 613d283 commit 3fe916a
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions llvm/lib/SYCLLowerIR/PrepareSYCLNativeCPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ static Function *addReplaceFunc(Module &M, StringRef Name, Type *StateType) {
Type *PtrTy = PointerType::get(Ctx, NativeCPUGlobalAS);
static FunctionType *FTy = FunctionType::get(RetTy, {DimTy, PtrTy}, false);
auto FCallee = M.getOrInsertFunction(Name, FTy);
auto *F = dyn_cast<Function>(FCallee.getCallee());
auto *F = cast<Function>(FCallee.getCallee());
IRBuilder<> Builder(Ctx);
BasicBlock *BB = BasicBlock::Create(Ctx, "entry", F);
Builder.SetInsertPoint(BB);
Expand Down Expand Up @@ -366,9 +366,7 @@ PreservedAnalyses PrepareSYCLNativeCPUPass::run(Module &M,
if (!Glob)
continue;
for (const auto &Use : Glob->uses()) {
auto I = dyn_cast<CallInst>(Use.getUser());
if (!I)
report_fatal_error("Unsupported Value in SYCL Native CPU\n");
auto *I = cast<CallInst>(Use.getUser());
if (!IsNativeCPUKernel(I->getFunction())) {
// only use the threadlocal if we have kernels calling builtins
// indirectly
Expand Down Expand Up @@ -417,9 +415,7 @@ PreservedAnalyses PrepareSYCLNativeCPUPass::run(Module &M,
Function *const Glob = Entry.first;
for (const auto &Use : Glob->uses()) {
auto *ReplaceFunc = getReplaceFunc(M, Entry.second.first, StateType);
auto I = dyn_cast<CallInst>(Use.getUser());
if (!I)
report_fatal_error("Unsupported Value in SYCL Native CPU\n");
auto *I = cast<CallInst>(Use.getUser());
auto *Arg = ConstantInt::get(Type::getInt32Ty(M.getContext()),
Entry.second.second);
auto *NewI = CallInst::Create(
Expand Down

0 comments on commit 3fe916a

Please sign in to comment.