[CodeGen] Fix potential null pointer dereference. NFC.

ScalarEvolution::getSCEV dereferences its argument, s.t. passing nullptr
leads to undefined behaviour.

Check for nullptr before calling it instead of checking its argument
afterwards.

llvm-svn: 336350
This commit is contained in:
Michael Kruse 2018-07-05 13:44:50 +00:00
parent 8ac85d9a11
commit 9f305371d9
1 changed files with 5 additions and 3 deletions

View File

@ -160,11 +160,13 @@ static llvm::Value *getMemAccInstPointerOperand(Instruction *Inst) {
void ScopAnnotator::annotateSecondLevel(llvm::Instruction *Inst,
llvm::Value *BasePtr) {
auto *PtrSCEV = SE->getSCEV(getMemAccInstPointerOperand(Inst));
Value *Ptr = getMemAccInstPointerOperand(Inst);
if (!Ptr)
return;
auto *PtrSCEV = SE->getSCEV(Ptr);
auto *BasePtrSCEV = SE->getPointerBase(PtrSCEV);
if (!PtrSCEV)
return;
auto SecondLevelAliasScope = SecondLevelAliasScopeMap.lookup(PtrSCEV);
auto SecondLevelOtherAliasScopeList =
SecondLevelOtherAliasScopeListMap.lookup(PtrSCEV);