[cfe-commits] r122670 - in /cfe/trunk: lib/CodeGen/CGStmt.cpp lib/Sema/SemaDecl.cpp test/Sema/asm.c

Rafael Espindola rafael.espindola at gmail.com
Sat Jan 1 13:47:03 PST 2011


Author: rafael
Date: Sat Jan  1 15:47:03 2011
New Revision: 122670

URL: http://llvm.org/viewvc/llvm-project?rev=122670&view=rev
Log:
Produce a better error message for invalid register names.

Modified:
    cfe/trunk/lib/CodeGen/CGStmt.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/asm.c

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=122670&r1=122669&r2=122670&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Sat Jan  1 15:47:03 2011
@@ -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;

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=122670&r1=122669&r2=122670&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Jan  1 15:47:03 2011
@@ -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.

Modified: cfe/trunk/test/Sema/asm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/asm.c?rev=122670&r1=122669&r2=122670&view=diff
==============================================================================
--- cfe/trunk/test/Sema/asm.c (original)
+++ cfe/trunk/test/Sema/asm.c Sat Jan  1 15:47:03 2011
@@ -91,3 +91,7 @@
   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}}
+}





More information about the cfe-commits mailing list