Produce a better error message for invalid register names.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@122670 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp
index a46a412..8ccd289 100644
--- a/lib/CodeGen/CGStmt.cpp
+++ b/lib/CodeGen/CGStmt.cpp
@@ -937,10 +937,7 @@
   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;
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 62262bc..abd6319 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -2995,8 +2995,12 @@
   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.