Skip to content

Commit cadedfb

Browse files
authored
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.
1 parent 648654d commit cadedfb

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

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)