diff --git a/llvm/lib/Target/NVPTX/SYCL/GlobalOffset.cpp b/llvm/lib/Target/NVPTX/SYCL/GlobalOffset.cpp index 16552eca8a5f..e0ae3795b4fb 100644 --- a/llvm/lib/Target/NVPTX/SYCL/GlobalOffset.cpp +++ b/llvm/lib/Target/NVPTX/SYCL/GlobalOffset.cpp @@ -342,8 +342,10 @@ class GlobalOffset : public ModulePass { continue; // Get a pointer to the entry point function from the metadata. - auto FuncConstant = - dyn_cast(MetadataNode->getOperand(0)); + const auto &FuncOperand = MetadataNode->getOperand(0); + if (!FuncOperand) + continue; + auto FuncConstant = dyn_cast(FuncOperand); if (!FuncConstant) continue; auto Func = dyn_cast(FuncConstant->getValue()); diff --git a/llvm/lib/Target/NVPTX/SYCL/LocalAccessorToSharedMemory.cpp b/llvm/lib/Target/NVPTX/SYCL/LocalAccessorToSharedMemory.cpp index a98293e0b487..00da01587009 100644 --- a/llvm/lib/Target/NVPTX/SYCL/LocalAccessorToSharedMemory.cpp +++ b/llvm/lib/Target/NVPTX/SYCL/LocalAccessorToSharedMemory.cpp @@ -65,6 +65,8 @@ class LocalAccessorToSharedMemory : public ModulePass { // Get a pointer to the entry point function from the metadata. const MDOperand &FuncOperand = MetadataNode->getOperand(0); + if (!FuncOperand) + continue; auto FuncConstant = dyn_cast(FuncOperand); if (!FuncConstant) continue;