Produce a better error message for invalid register names.

llvm-svn: 122670
This commit is contained in:
Rafael Espindola 2011-01-01 21:47:03 +00:00
parent 5734edc109
commit 478abcab3d
3 changed files with 10 additions and 5 deletions

View File

@ -937,10 +937,7 @@ AddVariableConstraints(const std::string &Constraint, const Expr &AsmExpr,
if (!Attr)
return Constraint;
llvm::StringRef Register = Attr->getLabel();
if (!Target.isValidGCCRegisterName(Register)) {
CGM.ErrorUnsupported(Variable, "__asm__");
return Constraint;
}
assert(Target.isValidGCCRegisterName(Register));
if (Constraint != "r") {
CGM.ErrorUnsupported(&Stmt, "__asm__");
return Constraint;

View File

@ -2995,8 +2995,12 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC,
if (Expr *E = (Expr*)D.getAsmLabel()) {
// The parser guarantees this is a string.
StringLiteral *SE = cast<StringLiteral>(E);
llvm::StringRef Label = SE->getString();
if (S->getFnParent() != 0 &&
!Context.Target.isValidGCCRegisterName(Label))
Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) << Label;
NewVD->addAttr(::new (Context) AsmLabelAttr(SE->getStrTokenLoc(0),
Context, SE->getString()));
Context, Label));
}
// Diagnose shadowed variables before filtering for scope.

View File

@ -91,3 +91,7 @@ void test9(int i) {
asm("" : [foo] "=r" (i), "=r"(i) : "1[foo]"(i)); // expected-error{{invalid input constraint '1[foo]' in asm}}
asm("" : [foo] "=r" (i), "=r"(i) : "[foo]1"(i)); // expected-error{{invalid input constraint '[foo]1' in asm}}
}
void test10(void){
register unsigned long long bar asm("foo"); // expected-error {{unknown register name 'foo' in asm}}
}