aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-03-11 00:23:13 +0000
committerChris Lattner <sabre@nondot.org>2009-03-11 00:23:13 +0000
commit85759278332404e96d4bb89d0e976e46158cd026 (patch)
treebbbacc9a2da3f7200108fc5542e75b961c1913a8 /lib
parented6c17617998e38b146479fc0b7a3baa636c7e61 (diff)
fix PR3258 by rejecting invalid numeric operands.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66618 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/AST/Stmt.cpp24
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp
index 4156af6ef9..cc120a684c 100644
--- a/lib/AST/Stmt.cpp
+++ b/lib/AST/Stmt.cpp
@@ -143,6 +143,17 @@ std::string AsmStmt::getOutputConstraint(unsigned i) const {
Constraints[i]->getByteLength());
}
+/// getNumPlusOperands - Return the number of output operands that have a "+"
+/// constraint.
+unsigned AsmStmt::getNumPlusOperands() const {
+ unsigned Res = 0;
+ for (unsigned i = 0, e = getNumOutputs(); i != e; ++i)
+ if (isOutputPlusConstraint(i))
+ ++Res;
+ return Res;
+}
+
+
Expr *AsmStmt::getInputExpr(unsigned i) {
return cast<Expr>(Exprs[i + NumOutputs]);
@@ -266,12 +277,15 @@ unsigned AsmStmt::AnalyzeAsmString(llvm::SmallVectorImpl<AsmStringPiece>&Pieces,
char *End;
unsigned long N = strtoul(CurPtr-1, &End, 10);
assert(End != CurPtr-1 && "We know that EscapedChar is a digit!");
- CurPtr = End;
-
- // FIXME: This should be caught during Sema.
- //unsigned NumOperands = S.getNumOutputs() + S.getNumInputs();
- //assert(N < NumOperands && "Operand number out of range!");
+ unsigned NumOperands =
+ getNumOutputs() + getNumPlusOperands() + getNumInputs();
+ if (N >= NumOperands) {
+ DiagOffs = CurPtr-StrStart-1;
+ return diag::err_asm_invalid_operand_number;
+ }
+
+ CurPtr = End;
Pieces.push_back(AsmStringPiece(N, Modifier));
continue;
}