Skip to content

Commit a341dc4

Browse files
maarquitos14jsji
authored andcommitted
Prevent invalid cast (#2987)
Not all SPIRVValue are SPIRVInstruction. For example, a SPIRVType is a SPIRVValue but not a SPIRVInstruction, so the cast is undefined behavior. Prevent invalid casts by checking if SV is indeed a SPIRVInstruction before doing the cast. Original commit: KhronosGroup/SPIRV-LLVM-Translator@cadedfbbbf8cf1c
1 parent 1f6a5a2 commit a341dc4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

llvm-spirv/lib/SPIRV/SPIRVToLLVMDbgTran.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,10 @@ void SPIRVToLLVMDbgTran::transDbgInfo(const SPIRVValue *SV, Value *V) {
159159
return;
160160

161161
if (Instruction *I = dyn_cast<Instruction>(V)) {
162-
const SPIRVInstruction *SI = static_cast<const SPIRVInstruction *>(SV);
163-
I->setDebugLoc(transDebugScope(SI));
162+
if (SV->isInst()) {
163+
const SPIRVInstruction *SI = static_cast<const SPIRVInstruction *>(SV);
164+
I->setDebugLoc(transDebugScope(SI));
165+
}
164166
}
165167
}
166168

0 commit comments

Comments
 (0)