Skip to content

Commit ebe3daf

Browse files
committed
Fix null reference exception
1 parent ee9783c commit ebe3daf

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/Transform/Clang/LoopDistribution.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ class ASTVisitor : public RecursiveASTVisitor<ASTVisitor> {
150150
: nullptr;
151151
};
152152
mGetInstructionFunction = [Matcher](Instruction *I) {
153-
return cast<Instruction>((**Matcher)[I]);
153+
auto Instr = (**Matcher)[I];
154+
return Instr
155+
? cast<Instruction>(Instr)
156+
: nullptr;
154157
};
155158
}
156159

@@ -310,9 +313,14 @@ class ASTVisitor : public RecursiveASTVisitor<ASTVisitor> {
310313

311314
bool isSplittableDependence(Instruction *Read, Instruction *Write,
312315
const unsigned LoopDepth) const {
316+
const auto ServerWrite = mGetInstructionFunction(Write);
317+
const auto ServerRead = mGetInstructionFunction(Read);
318+
if (!ServerWrite || !ServerRead) {
319+
return false;
320+
}
313321
// TODO: Probably true instead of false
314-
const auto Dependence = mDependence->depends(
315-
mGetInstructionFunction(Write), mGetInstructionFunction(Read), false);
322+
const auto Dependence =
323+
mDependence->depends(ServerWrite, ServerRead, false);
316324
if (!Dependence) {
317325
return false;
318326
}

0 commit comments

Comments
 (0)