Skip to content

Commit 0655292

Browse files
[SPIR-V] Fix an issue with casting types in debug-info extension implementation (#129721)
This PR fixes an issue in debug-info extension implementation (namely, a wrong assumption that all pointee types are basic types). The reproducer is added to an existing test case of "pointers with debug-info".
1 parent 3105290 commit 0655292

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ bool SPIRVEmitNonSemanticDI::emitGlobalDI(MachineFunction &MF) {
158158
// pointed on from other DI types
159159
// DerivedType->getBaseType is null when pointer
160160
// is representing a void type
161-
if (DerivedType->getBaseType())
162-
BasicTypes.insert(
163-
cast<DIBasicType>(DerivedType->getBaseType()));
161+
if (auto *BT = dyn_cast_or_null<DIBasicType>(
162+
DerivedType->getBaseType()))
163+
BasicTypes.insert(BT);
164164
}
165165
}
166166
}
@@ -330,7 +330,7 @@ bool SPIRVEmitNonSemanticDI::emitGlobalDI(MachineFunction &MF) {
330330
// If the Pointer is representing a void type it's getBaseType
331331
// is a nullptr
332332
const auto *MaybeNestedBasicType =
333-
cast_or_null<DIBasicType>(PointerDerivedType->getBaseType());
333+
dyn_cast_or_null<DIBasicType>(PointerDerivedType->getBaseType());
334334
if (MaybeNestedBasicType) {
335335
for (const auto &BasicTypeRegPair : BasicTypeRegPairs) {
336336
const auto &[DefinedBasicType, BasicTypeReg] = BasicTypeRegPair;

llvm/test/CodeGen/SPIRV/debug-info/debug-type-pointer.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,4 @@ define spir_func i32 @test1() !dbg !72 {
278278
!98 = !DILocalVariable(name: "arr1", scope: !72, file: !3, line: 35, type: !67)
279279
!99 = !DILocation(line: 35, column: 7, scope: !72)
280280
!100 = !DILocation(line: 36, column: 3, scope: !72)
281+
!101 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !67, size: 32, dwarfAddressSpace: 4)

0 commit comments

Comments
 (0)