summaryrefslogtreecommitdiff
path: root/utils/TableGen/CodeGenInstruction.cpp
diff options
context:
space:
mode:
authorTim Northover <tnorthover@apple.com>2014-03-29 09:03:22 +0000
committerTim Northover <tnorthover@apple.com>2014-03-29 09:03:22 +0000
commit69bd9577fc423edea13479eaacf7b1844faa6c6a (patch)
tree7cc01ef9f8b97cfbbc4d1fcf0748c338d8c56e47 /utils/TableGen/CodeGenInstruction.cpp
parent483b0e996c4d7b72cffd3ceacc0636758749940e (diff)
downloadllvm-69bd9577fc423edea13479eaacf7b1844faa6c6a.tar.gz
llvm-69bd9577fc423edea13479eaacf7b1844faa6c6a.tar.bz2
llvm-69bd9577fc423edea13479eaacf7b1844faa6c6a.tar.xz
TableGen: avoid dereferencing nullptr variable
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
Diffstat (limited to 'utils/TableGen/CodeGenInstruction.cpp')
-rw-r--r--utils/TableGen/CodeGenInstruction.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/utils/TableGen/CodeGenInstruction.cpp b/utils/TableGen/CodeGenInstruction.cpp
index dbe3e69c8e..fb4785b601 100644
--- a/utils/TableGen/CodeGenInstruction.cpp
+++ b/utils/TableGen/CodeGenInstruction.cpp
@@ -436,6 +436,7 @@ 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
@@ -443,19 +444,25 @@ bool CodeGenInstAlias::tryAliasOpMatch(DagInit *Result, unsigned AliasOpNo,
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;
}
@@ -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;
@@ -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;
}