[ms-inline asm] Have the LookupInlineAsmIdentifier() callback function return a

*NamedDecl.  In turn, build the expressions after we're finished parsing the
asm.  This avoids a crasher if the lookup fails.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166212 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chad Rosier
2012-10-18 19:39:30 +00:00
parent 8c1dcdf26d
commit c8dd27e583
2 changed files with 15 additions and 28 deletions

View File

@@ -34,8 +34,7 @@ class Twine;
/// MCAsmParserSemaCallback - Generic Sema callback for assembly parser. /// MCAsmParserSemaCallback - Generic Sema callback for assembly parser.
class MCAsmParserSemaCallback { class MCAsmParserSemaCallback {
public: public:
virtual void *LookupInlineAsmIdentifier(StringRef Name, void *Loc, virtual void *LookupInlineAsmIdentifier(StringRef Name, void *Loc) = 0;
void **IdentifierInfoPtr) = 0;
}; };
/// MCAsmParser - Generic assembler parser interface, for use by target specific /// MCAsmParser - Generic assembler parser interface, for use by target specific
@@ -89,9 +88,8 @@ public:
/// ParseMSInlineAsm - Parse ms-style inline assembly. /// ParseMSInlineAsm - Parse ms-style inline assembly.
virtual bool ParseMSInlineAsm(void *AsmLoc, std::string &AsmString, virtual bool ParseMSInlineAsm(void *AsmLoc, std::string &AsmString,
unsigned &NumOutputs, unsigned &NumInputs, unsigned &NumOutputs, unsigned &NumInputs,
SmallVectorImpl<void *> &Names, SmallVectorImpl<void *> &OpDecls,
SmallVectorImpl<std::string> &Constraints, SmallVectorImpl<std::string> &Constraints,
SmallVectorImpl<void *> &Exprs,
SmallVectorImpl<std::string> &Clobbers, SmallVectorImpl<std::string> &Clobbers,
const MCInstrInfo *MII, const MCInstrInfo *MII,
const MCInstPrinter *IP, const MCInstPrinter *IP,

View File

@@ -190,9 +190,8 @@ public:
bool ParseMSInlineAsm(void *AsmLoc, std::string &AsmString, bool ParseMSInlineAsm(void *AsmLoc, std::string &AsmString,
unsigned &NumOutputs, unsigned &NumInputs, unsigned &NumOutputs, unsigned &NumInputs,
SmallVectorImpl<void *> &Names, SmallVectorImpl<void *> &OpDecls,
SmallVectorImpl<std::string> &Constraints, SmallVectorImpl<std::string> &Constraints,
SmallVectorImpl<void *> &Exprs,
SmallVectorImpl<std::string> &Clobbers, SmallVectorImpl<std::string> &Clobbers,
const MCInstrInfo *MII, const MCInstrInfo *MII,
const MCInstPrinter *IP, const MCInstPrinter *IP,
@@ -3592,19 +3591,16 @@ public:
bool AsmParser::ParseMSInlineAsm(void *AsmLoc, std::string &AsmString, bool AsmParser::ParseMSInlineAsm(void *AsmLoc, std::string &AsmString,
unsigned &NumOutputs, unsigned &NumInputs, unsigned &NumOutputs, unsigned &NumInputs,
SmallVectorImpl<void *> &Names, SmallVectorImpl<void *> &OpDecls,
SmallVectorImpl<std::string> &Constraints, SmallVectorImpl<std::string> &Constraints,
SmallVectorImpl<void *> &Exprs,
SmallVectorImpl<std::string> &Clobbers, SmallVectorImpl<std::string> &Clobbers,
const MCInstrInfo *MII, const MCInstrInfo *MII,
const MCInstPrinter *IP, const MCInstPrinter *IP,
MCAsmParserSemaCallback &SI) { MCAsmParserSemaCallback &SI) {
SmallVector<void*, 4> Inputs; SmallVector<void*, 4> InputDecls;
SmallVector<void*, 4> Outputs; SmallVector<void*, 4> OutputDecls;
SmallVector<std::string, 4> InputConstraints; SmallVector<std::string, 4> InputConstraints;
SmallVector<std::string, 4> OutputConstraints; SmallVector<std::string, 4> OutputConstraints;
SmallVector<void*, 4> InputExprs;
SmallVector<void*, 4> OutputExprs;
std::set<std::string> ClobberRegs; std::set<std::string> ClobberRegs;
SmallVector<struct AsmOpRewrite, 4> AsmStrRewrites; SmallVector<struct AsmOpRewrite, 4> AsmStrRewrites;
@@ -3647,24 +3643,20 @@ bool AsmParser::ParseMSInlineAsm(void *AsmLoc, std::string &AsmString,
} }
// Expr/Input or Output. // Expr/Input or Output.
void *II; void *OpDecl = SI.LookupInlineAsmIdentifier(Operand->getName(), AsmLoc);
void *ExprResult = SI.LookupInlineAsmIdentifier(Operand->getName(), if (OpDecl) {
AsmLoc, &II);
if (ExprResult) {
bool isOutput = (i == 1) && Desc.mayStore(); bool isOutput = (i == 1) && Desc.mayStore();
if (isOutput) { if (isOutput) {
std::string Constraint = "="; std::string Constraint = "=";
++InputIdx; ++InputIdx;
Outputs.push_back(II); OutputDecls.push_back(OpDecl);
OutputExprs.push_back(ExprResult);
Constraint += Operand->getConstraint().str(); Constraint += Operand->getConstraint().str();
OutputConstraints.push_back(Constraint); OutputConstraints.push_back(Constraint);
AsmStrRewrites.push_back(AsmOpRewrite(AOK_Output, AsmStrRewrites.push_back(AsmOpRewrite(AOK_Output,
Operand->getStartLoc(), Operand->getStartLoc(),
Operand->getNameLen())); Operand->getNameLen()));
} else { } else {
Inputs.push_back(II); InputDecls.push_back(OpDecl);
InputExprs.push_back(ExprResult);
InputConstraints.push_back(Operand->getConstraint().str()); InputConstraints.push_back(Operand->getConstraint().str());
AsmStrRewrites.push_back(AsmOpRewrite(AOK_Input, AsmStrRewrites.push_back(AsmOpRewrite(AOK_Input,
Operand->getStartLoc(), Operand->getStartLoc(),
@@ -3680,8 +3672,8 @@ bool AsmParser::ParseMSInlineAsm(void *AsmLoc, std::string &AsmString,
} }
// Set the number of Outputs and Inputs. // Set the number of Outputs and Inputs.
NumOutputs = Outputs.size(); NumOutputs = OutputDecls.size();
NumInputs = Inputs.size(); NumInputs = InputDecls.size();
// Set the unique clobbers. // Set the unique clobbers.
for (std::set<std::string>::iterator I = ClobberRegs.begin(), for (std::set<std::string>::iterator I = ClobberRegs.begin(),
@@ -3691,18 +3683,15 @@ bool AsmParser::ParseMSInlineAsm(void *AsmLoc, std::string &AsmString,
// Merge the various outputs and inputs. Output are expected first. // Merge the various outputs and inputs. Output are expected first.
if (NumOutputs || NumInputs) { if (NumOutputs || NumInputs) {
unsigned NumExprs = NumOutputs + NumInputs; unsigned NumExprs = NumOutputs + NumInputs;
Names.resize(NumExprs); OpDecls.resize(NumExprs);
Constraints.resize(NumExprs); Constraints.resize(NumExprs);
Exprs.resize(NumExprs);
for (unsigned i = 0; i < NumOutputs; ++i) { for (unsigned i = 0; i < NumOutputs; ++i) {
Names[i] = Outputs[i]; OpDecls[i] = OutputDecls[i];
Constraints[i] = OutputConstraints[i]; Constraints[i] = OutputConstraints[i];
Exprs[i] = OutputExprs[i];
} }
for (unsigned i = 0, j = NumOutputs; i < NumInputs; ++i, ++j) { for (unsigned i = 0, j = NumOutputs; i < NumInputs; ++i, ++j) {
Names[j] = Inputs[i]; OpDecls[j] = InputDecls[i];
Constraints[j] = InputConstraints[i]; Constraints[j] = InputConstraints[i];
Exprs[j] = InputExprs[i];
} }
} }