diff --git a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp --- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp @@ -4273,6 +4273,11 @@ assert(MDN->getNumOperands() == 3); const Metadata *MD0 = MDN->getOperand(0).get(); + // Allow degenerated annotations created by OpenMP offloading with old + // CUDA versions. + if (!MD0) + continue; + const auto *MDV0 = cast(MD0)->getValue(); const auto *MDFn = cast(MDV0); if (MDFn != F) diff --git a/llvm/test/CodeGen/NVPTX/param-vectorize-device.ll b/llvm/test/CodeGen/NVPTX/param-vectorize-device.ll --- a/llvm/test/CodeGen/NVPTX/param-vectorize-device.ll +++ b/llvm/test/CodeGen/NVPTX/param-vectorize-device.ll @@ -799,3 +799,7 @@ %oldret = insertvalue [4 x i32] %7, i32 %4, 3 ret [4 x i32] %oldret } + +!nvvm.annotations = !{!0} + +!0 = !{null, !"foobar", i32 0}