[driver, ms-inline asm] MS-Style inline assembly is controlled by the
-fasm-blocks flag, not the -fms-extensions flag.
rdar://12808010

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169422 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/LangOptions.def b/include/clang/Basic/LangOptions.def
index fc78e92..f180e31 100644
--- a/include/clang/Basic/LangOptions.def
+++ b/include/clang/Basic/LangOptions.def
@@ -45,6 +45,7 @@
 LANGOPT(C11               , 1, 0, "C11")
 LANGOPT(MicrosoftExt      , 1, 0, "Microsoft extensions")
 LANGOPT(MicrosoftMode     , 1, 0, "Microsoft compatibility mode")
+LANGOPT(AsmBlocks         , 1, 0, "Microsoft inline asm blocks")
 LANGOPT(Borland           , 1, 0, "Borland extensions")
 LANGOPT(CPlusPlus         , 1, 0, "C++")
 LANGOPT(CPlusPlus0x       , 1, 0, "C++0x")
diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td
index 7cd550e..432b754 100644
--- a/include/clang/Driver/Options.td
+++ b/include/clang/Driver/Options.td
@@ -300,7 +300,7 @@
 def fno_thread_sanitizer : Flag<["-"], "fno-thread-sanitizer">, Group<f_Group>;
 def fasm : Flag<["-"], "fasm">, Group<f_Group>;
 
-def fasm_blocks : Flag<["-"], "fasm-blocks">, Group<f_Group>;
+def fasm_blocks : Flag<["-"], "fasm-blocks">, Group<f_Group>, Flags<[CC1Option]>;
 def fno_asm_blocks : Flag<["-"], "fno-asm-blocks">, Group<f_Group>;
 
 def fassume_sane_operator_new : Flag<["-"], "fassume-sane-operator-new">, Group<f_Group>;
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 911a9dc..7506c4c 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -2942,9 +2942,10 @@
     CmdArgs.push_back("-fno-spell-checking");
 
 
-  // Silently ignore -fasm-blocks for now.
-  (void) Args.hasFlag(options::OPT_fasm_blocks, options::OPT_fno_asm_blocks,
-                      false);
+  // -fno-asm-blocks is default.
+  if (Args.hasFlag(options::OPT_fasm_blocks, options::OPT_fno_asm_blocks,
+                   false))
+    CmdArgs.push_back("-fasm-blocks");
 
   if (Arg *A = Args.getLastArg(options::OPT_fshow_overloads_EQ))
     A->render(Args, CmdArgs);
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index 0d886e2..9da28e5 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -1172,6 +1172,7 @@
   Opts.MicrosoftExt
     = Args.hasArg(OPT_fms_extensions) || Args.hasArg(OPT_fms_compatibility);
   Opts.MicrosoftMode = Args.hasArg(OPT_fms_compatibility);
+  Opts.AsmBlocks = Args.hasArg(OPT_fasm_blocks);
   Opts.MSCVersion = Args.getLastArgIntValue(OPT_fmsc_version, 0, Diags);
   Opts.Borland = Args.hasArg(OPT_fborland_extensions);
   Opts.WritableStrings = Args.hasArg(OPT_fwritable_strings);
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp
index d097d39..f6f5afe 100644
--- a/lib/Parse/ParseStmt.cpp
+++ b/lib/Parse/ParseStmt.cpp
@@ -1820,7 +1820,7 @@
   assert(Tok.is(tok::kw_asm) && "Not an asm stmt");
   SourceLocation AsmLoc = ConsumeToken();
 
-  if (getLangOpts().MicrosoftExt && Tok.isNot(tok::l_paren) &&
+  if (getLangOpts().AsmBlocks && Tok.isNot(tok::l_paren) &&
       !isTypeQualifier()) {
     msAsm = true;
     return ParseMicrosoftAsmStatement(AsmLoc);
diff --git a/test/CodeGen/ms-inline-asm-64.c b/test/CodeGen/ms-inline-asm-64.c
index a74ede0..d5df6c3 100644
--- a/test/CodeGen/ms-inline-asm-64.c
+++ b/test/CodeGen/ms-inline-asm-64.c
@@ -1,5 +1,5 @@
 // REQUIRES: x86-64-registered-target
-// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -O0 -fms-extensions -fenable-experimental-ms-inline-asm -w -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -O0 -fasm-blocks -fenable-experimental-ms-inline-asm -w -emit-llvm -o - | FileCheck %s
 
 void t1() {
   int var = 10;
diff --git a/test/CodeGen/ms-inline-asm.c b/test/CodeGen/ms-inline-asm.c
index d0e9a7b..f587afd 100644
--- a/test/CodeGen/ms-inline-asm.c
+++ b/test/CodeGen/ms-inline-asm.c
@@ -1,5 +1,5 @@
 // REQUIRES: x86-64-registered-target
-// RUN: %clang_cc1 %s -triple i386-apple-darwin10 -O0 -fms-extensions -fenable-experimental-ms-inline-asm -w -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple i386-apple-darwin10 -O0 -fasm-blocks -fenable-experimental-ms-inline-asm -w -emit-llvm -o - | FileCheck %s
 
 void t1() {
 // CHECK: @t1
@@ -201,7 +201,6 @@
 // CHECK: call void asm sideeffect inteldialect "mov eax, $$4", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
 }
 
-
 void t21() {
   __asm {
     __asm push ebx
diff --git a/test/Driver/ms-inline-asm.c b/test/Driver/ms-inline-asm.c
new file mode 100644
index 0000000..0383564
--- /dev/null
+++ b/test/Driver/ms-inline-asm.c
@@ -0,0 +1,15 @@
+// RUN: %clang -target x86_64-apple-darwin10 \
+// RUN:   -### -fsyntax-only -fasm-blocks %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-BLOCKS < %t %s
+
+// RUN: %clang -target x86_64-apple-darwin10 \
+// RUN:   -### -fsyntax-only -fno-asm-blocks -fasm-blocks %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-BLOCKS < %t %s
+
+// CHECK-BLOCKS: "-fasm-blocks"
+
+// RUN: %clang -target x86_64-apple-darwin10 \
+// RUN:   -### -fsyntax-only -fasm-blocks -fno-asm-blocks %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-NO-BLOCKS < %t %s
+
+// CHECK-NO-BLOCKS-NOT: "-fasm-blocks"
diff --git a/test/Parser/MicrosoftExtensions.c b/test/Parser/MicrosoftExtensions.c
index 7703999..a8e7b89 100644
--- a/test/Parser/MicrosoftExtensions.c
+++ b/test/Parser/MicrosoftExtensions.c
@@ -18,15 +18,6 @@
   return((void * __ptr32) (unsigned __int32) (ULONG_PTR)p );
 }
 
-void __forceinline InterlockedBitTestAndSet (long *Base, long Bit)
-{
-  __asm { // expected-warning {{MS-style inline assembly is not supported}}
-    mov eax, Bit
-    mov ecx, Base
-    lock bts [ecx], eax
-    setc al
-  };
-}
 _inline int foo99() { return 99; }
 
 void test_ms_alignof_alias() {
diff --git a/test/Parser/ms-inline-asm.c b/test/Parser/ms-inline-asm.c
index 0e8b317..280881a 100644
--- a/test/Parser/ms-inline-asm.c
+++ b/test/Parser/ms-inline-asm.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -verify -fms-extensions
+// RUN: %clang_cc1 %s -verify -fasm-blocks
 
 #define M __asm int 0x2c
 #define M2 int
diff --git a/test/Sema/ms-inline-asm.c b/test/Sema/ms-inline-asm.c
index f6a0fdc..8cdd547 100644
--- a/test/Sema/ms-inline-asm.c
+++ b/test/Sema/ms-inline-asm.c
@@ -1,5 +1,5 @@
 // REQUIRES: x86-64-registered-target
-// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -fms-extensions -fenable-experimental-ms-inline-asm -Wno-microsoft -verify -fsyntax-only
+// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -fasm-blocks -fenable-experimental-ms-inline-asm -Wno-microsoft -verify -fsyntax-only
 
 void t1(void) { 
  __asm __asm // expected-error {{__asm used with no assembly instructions}}