[cfe-commits] r134016 - in /cfe/trunk: include/clang/Basic/TargetInfo.h lib/Basic/TargetInfo.cpp lib/CodeGen/CGStmt.cpp lib/Sema/SemaStmt.cpp test/Sema/asm.c

Eric Christopher echristo at apple.com
Tue Jun 28 11:20:53 PDT 2011


Author: echristo
Date: Tue Jun 28 13:20:53 2011
New Revision: 134016

URL: http://llvm.org/viewvc/llvm-project?rev=134016&view=rev
Log:
Split out logic for valid clobbers and valid inline asm registers.

Fixes rdar://9281377

Modified:
    cfe/trunk/include/clang/Basic/TargetInfo.h
    cfe/trunk/lib/Basic/TargetInfo.cpp
    cfe/trunk/lib/CodeGen/CGStmt.cpp
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/Sema/asm.c

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=134016&r1=134015&r2=134016&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Tue Jun 28 13:20:53 2011
@@ -303,6 +303,11 @@
   /// __builtin_va_list, which is target-specific.
   virtual const char *getVAListDeclaration() const = 0;
 
+  /// isValidClobber - Returns whether the passed in string is
+  /// a valid clobber in an inline asm statement. This is used by
+  /// Sema.
+  bool isValidClobber(llvm::StringRef Name) const;
+
   /// isValidGCCRegisterName - Returns whether the passed in string
   /// is a valid register name according to GCC. This is used by Sema for
   /// inline asm statements.

Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=134016&r1=134015&r2=134016&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Tue Jun 28 13:20:53 2011
@@ -181,6 +181,14 @@
   return Name;
 }
 
+/// isValidClobber - Returns whether the passed in string is
+/// a valid clobber in an inline asm statement. This is used by
+/// Sema.
+bool TargetInfo::isValidClobber(llvm::StringRef Name) const {
+  return (isValidGCCRegisterName(Name) ||
+	  Name == "memory" || Name == "cc");
+}
+
 /// isValidGCCRegisterName - Returns whether the passed in string
 /// is a valid register name according to GCC. This is used by Sema for
 /// inline asm statements.
@@ -194,9 +202,6 @@
   // Get rid of any register prefix.
   Name = removeGCCRegisterPrefix(Name);
 
-  if (Name == "memory" || Name == "cc")
-    return true;
-
   getGCCRegNames(Names, NumNames);
 
   // If we have a number it maps to an entry in the register name array.

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=134016&r1=134015&r2=134016&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Tue Jun 28 13:20:53 2011
@@ -1558,6 +1558,7 @@
   for (unsigned i = 0, e = S.getNumClobbers(); i != e; i++) {
     llvm::StringRef Clobber = S.getClobber(i)->getString();
 
+    if (Clobber != "memory" && Clobber != "cc")
     Clobber = Target.getNormalizedGCCRegisterName(Clobber);
 
     if (i != 0 || NumConstraints != 0)

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=134016&r1=134015&r2=134016&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Tue Jun 28 13:20:53 2011
@@ -1990,7 +1990,7 @@
 
     llvm::StringRef Clobber = Literal->getString();
 
-    if (!Context.Target.isValidGCCRegisterName(Clobber))
+    if (!Context.Target.isValidClobber(Clobber))
       return StmtError(Diag(Literal->getLocStart(),
                   diag::err_asm_unknown_register_name) << Clobber);
   }
@@ -2350,4 +2350,3 @@
   assert(Block);
   return Owned(SEHFinallyStmt::Create(Context,Loc,Block));
 }
-

Modified: cfe/trunk/test/Sema/asm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/asm.c?rev=134016&r1=134015&r2=134016&view=diff
==============================================================================
--- cfe/trunk/test/Sema/asm.c (original)
+++ cfe/trunk/test/Sema/asm.c Tue Jun 28 13:20:53 2011
@@ -113,3 +113,7 @@
   _Bool b;
   asm volatile ("movb %%gs:%P2,%b0" : "=q"(b) : "0"(0), "i"(5L));
 }
+
+void test12(void) {
+  register int cc __asm ("cc"); // expected-error{{unknown register name 'cc' in asm}}
+}





More information about the cfe-commits mailing list