diff --git a/llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp b/llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp index ee98af5cffe4c..3c0d9cc3b91c0 100644 --- a/llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp +++ b/llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp @@ -158,9 +158,9 @@ bool SPIRVEmitNonSemanticDI::emitGlobalDI(MachineFunction &MF) { // pointed on from other DI types // DerivedType->getBaseType is null when pointer // is representing a void type - if (DerivedType->getBaseType()) - BasicTypes.insert( - cast(DerivedType->getBaseType())); + if (auto *BT = dyn_cast_or_null( + DerivedType->getBaseType())) + BasicTypes.insert(BT); } } } @@ -330,7 +330,7 @@ bool SPIRVEmitNonSemanticDI::emitGlobalDI(MachineFunction &MF) { // If the Pointer is representing a void type it's getBaseType // is a nullptr const auto *MaybeNestedBasicType = - cast_or_null(PointerDerivedType->getBaseType()); + dyn_cast_or_null(PointerDerivedType->getBaseType()); if (MaybeNestedBasicType) { for (const auto &BasicTypeRegPair : BasicTypeRegPairs) { const auto &[DefinedBasicType, BasicTypeReg] = BasicTypeRegPair; diff --git a/llvm/test/CodeGen/SPIRV/debug-info/debug-type-pointer.ll b/llvm/test/CodeGen/SPIRV/debug-info/debug-type-pointer.ll index 77faa56230876..93ea49afc6589 100644 --- a/llvm/test/CodeGen/SPIRV/debug-info/debug-type-pointer.ll +++ b/llvm/test/CodeGen/SPIRV/debug-info/debug-type-pointer.ll @@ -278,3 +278,4 @@ define spir_func i32 @test1() !dbg !72 { !98 = !DILocalVariable(name: "arr1", scope: !72, file: !3, line: 35, type: !67) !99 = !DILocation(line: 35, column: 7, scope: !72) !100 = !DILocation(line: 36, column: 3, scope: !72) +!101 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !67, size: 32, dwarfAddressSpace: 4)