return getOutputConstraint(i)[0] == '+';
}
+ /// getNumPlusOperands - Return the number of output operands that have a "+"
+ /// constraint.
+ unsigned getNumPlusOperands() const;
+
//===--- Input operands ---===//
unsigned getNumInputs() const { return NumInputs; }
DIAG(err_asm_unterminated_symbolic_operand_name, ERROR,
"unterminated symbolic operand name in inline assembly string")
DIAG(err_asm_empty_symbolic_operand_name, ERROR,
- "empty symbolic operand name in inline assembly string")
\ No newline at end of file
+ "empty symbolic operand name in inline assembly string")
+DIAG(err_asm_invalid_operand_number, ERROR,
+ "invalid operand number in inline asm string")
\ No newline at end of file
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]);
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;
}
asm("nop" : : "er"(i));
}
-void asm_string_tests() {
+void asm_string_tests(int i) {
asm("%!"); // simple asm string, %! is not an error.
asm("%!" : ); // expected-error {{invalid % escape in inline assembly string}}
asm("xyz %" : ); // expected-error {{invalid % escape in inline assembly string}}
asm ("%[somename]" :: "i"(4)); // expected-error {{unknown symbolic operand name in inline assembly string}}
asm ("%[somename" :: "i"(4)); // expected-error {{unterminated symbolic operand name in inline assembly string}}
asm ("%[]" :: "i"(4)); // expected-error {{empty symbolic operand name in inline assembly string}}
+
+ // PR3258
+ asm("%9" :: "i"(4)); // expected-error {{invalid operand number in inline asm string}}
+ asm("%1" : "+r"(i)); // ok, referring to input.
}