[cfe-commits] r162050 - in /cfe/trunk: lib/Sema/SemaStmt.cpp test/CodeGen/ms-inline-asm.c

Chad Rosier mcrosier at apple.com
Thu Aug 16 15:25:38 PDT 2012


Author: mcrosier
Date: Thu Aug 16 17:25:38 2012
New Revision: 162050

URL: http://llvm.org/viewvc/llvm-project?rev=162050&view=rev
Log:
[ms-inline asm] Add a helper function, isMSAsmKeyword().

These require special handling, which we don't currently handle.  This is being
put in place to ensure we don't do invalid symbol table lookups or try to parse
invalid assembly.  The test cases just makes sure the latter isn't happening.

Modified:
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/CodeGen/ms-inline-asm.c

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=162050&r1=162049&r2=162050&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Thu Aug 16 17:25:38 2012
@@ -2762,6 +2762,17 @@
   return Owned(NS);
 }
 
+// isMSAsmKeyword - Return true if this is an MS-style inline asm keyword. These
+// require special handling.
+static bool isMSAsmKeyword(StringRef Name) {
+  bool Ret = llvm::StringSwitch<bool>(Name)
+    .Cases("EVEN", "ALIGN", true) // Alignment directives.
+    .Cases("LENGTH", "SIZE", "TYPE", true) // Type and variable sizes.
+    .Case("_emit", true) // _emit Pseudoinstruction.
+    .Default(false);
+  return Ret;
+}
+
 static void patchMSAsmStrings(Sema &SemaRef, bool &IsSimple,
                               SourceLocation AsmLoc,
                               ArrayRef<Token> AsmToks,
@@ -2795,7 +2806,14 @@
     if (isNewAsm) {
       AsmRegs[NumAsmStrings].resize(AsmToks.size());
       AsmNames[NumAsmStrings].resize(AsmToks.size());
-      Asm = AsmToks[i].getIdentifierInfo()->getName().str();
+
+      StringRef Piece = AsmToks[i].getIdentifierInfo()->getName();
+      // MS-style inline asm keywords require special handling.
+      if (isMSAsmKeyword(Piece))
+        IsSimple = false;
+
+      // TODO: Verify this is a valid opcode.
+      Asm = Piece;
       continue;
     }
 
@@ -2834,6 +2852,13 @@
 
       IsSimple = false;
 
+      // MS-style inline asm keywords require special handling.
+      if (isMSAsmKeyword(Name)) {
+        IsSimple = false;
+        Asm += Name;
+        break;
+      }
+
       // FIXME: Why are we missing this segment register?
       if (Name == "fs") {
         Asm += Name;

Modified: cfe/trunk/test/CodeGen/ms-inline-asm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ms-inline-asm.c?rev=162050&r1=162049&r2=162050&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/ms-inline-asm.c (original)
+++ cfe/trunk/test/CodeGen/ms-inline-asm.c Thu Aug 16 17:25:38 2012
@@ -98,3 +98,23 @@
 // CHECK: [[RET:%[a-zA-Z0-9]+]] = load i32* [[J]], align 4
 // CHECK: ret i32 [[RET]]
 }
+
+void t12(void) {
+  __asm EVEN
+  __asm ALIGN
+}
+
+void t13(void) {
+  __asm {
+    _emit 0x4A
+    _emit 0x43
+    _emit 0x4B
+  }
+}
+
+void t14(void) {
+  unsigned arr[10];
+  __asm LENGTH arr ; sizeof(arr)/sizeof(arr[0])
+  __asm SIZE arr   ; sizeof(arr)
+  __asm TYPE arr   ; sizeof(arr[0])
+}





More information about the cfe-commits mailing list