]> granicus.if.org Git - clang/commitdiff
[ms-inline asm] Add a helper function, isMSAsmKeyword().
authorChad Rosier <mcrosier@apple.com>
Thu, 16 Aug 2012 22:25:38 +0000 (22:25 +0000)
committerChad Rosier <mcrosier@apple.com>
Thu, 16 Aug 2012 22:25:38 +0000 (22:25 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162050 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaStmt.cpp
test/CodeGen/ms-inline-asm.c

index 74d1c596ad0baa60d0a4da15c7644f42cea9a786..5493e343c6a262d9b0f6e6393449285b6e8326c9 100644 (file)
@@ -2762,6 +2762,17 @@ StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, bool IsSimple,
   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 @@ static void patchMSAsmStrings(Sema &SemaRef, bool &IsSimple,
     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 @@ static void patchMSAsmStrings(Sema &SemaRef, bool &IsSimple,
 
       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;
index 310fbd1e008eb07ce5fbcf300bbacd924949549b..c140d60551d9928604b62f3efe2905317a4f57b0 100644 (file)
@@ -98,3 +98,23 @@ unsigned t11(void) {
 // 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])
+}