Skip to content

Commit

Permalink
TableGen: avoid dereferencing nullptr variable
Browse files Browse the repository at this point in the history
ARM64 ended up reaching odder parts of TableGen alias generation than
current backends and caused a segfault.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205089 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
TNorthover committed Mar 29, 2014
1 parent 483b0e9 commit 69bd957
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions utils/TableGen/CodeGenInstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,26 +436,33 @@ bool CodeGenInstAlias::tryAliasOpMatch(DagInit *Result, unsigned AliasOpNo,
ResultOperand &ResOp) {
Init *Arg = Result->getArg(AliasOpNo);
DefInit *ADI = dyn_cast<DefInit>(Arg);
Record *ResultRecord = ADI ? ADI->getDef() : 0;

if (ADI && ADI->getDef() == InstOpRec) {
// If the operand is a record, it must have a name, and the record type
// must match up with the instruction's argument type.
if (Result->getArgName(AliasOpNo).empty())
PrintFatalError(Loc, "result argument #" + utostr(AliasOpNo) +
" must have a name!");
ResOp = ResultOperand(Result->getArgName(AliasOpNo), ADI->getDef());
ResOp = ResultOperand(Result->getArgName(AliasOpNo), ResultRecord);
return true;
}

// For register operands, the source register class can be a subclass
// of the instruction register class, not just an exact match.
if (InstOpRec->isSubClassOf("RegisterOperand"))
InstOpRec = InstOpRec->getValueAsDef("RegClass");

if (ADI && ADI->getDef()->isSubClassOf("RegisterOperand"))
ADI = ADI->getDef()->getValueAsDef("RegClass")->getDefInit();

if (ADI && ADI->getDef()->isSubClassOf("RegisterClass")) {
if (!InstOpRec->isSubClassOf("RegisterClass"))
return false;
if (!T.getRegisterClass(InstOpRec)
.hasSubClass(&T.getRegisterClass(ADI->getDef())))
return false;
ResOp = ResultOperand(Result->getArgName(AliasOpNo), ADI->getDef());
ResOp = ResultOperand(Result->getArgName(AliasOpNo), ResultRecord);
return true;
}

Expand All @@ -468,9 +475,6 @@ bool CodeGenInstAlias::tryAliasOpMatch(DagInit *Result, unsigned AliasOpNo,
InstOpRec = cast<DefInit>(DI->getArg(0))->getDef();
}

if (InstOpRec->isSubClassOf("RegisterOperand"))
InstOpRec = InstOpRec->getValueAsDef("RegClass");

if (!InstOpRec->isSubClassOf("RegisterClass"))
return false;

Expand All @@ -484,7 +488,7 @@ bool CodeGenInstAlias::tryAliasOpMatch(DagInit *Result, unsigned AliasOpNo,
PrintFatalError(Loc, "result fixed register argument must "
"not have a name!");

ResOp = ResultOperand(ADI->getDef());
ResOp = ResultOperand(ResultRecord);
return true;
}

Expand Down

0 comments on commit 69bd957

Please sign in to comment.