Turns #import in MS Mode into an error.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153009 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticLexKinds.td b/include/clang/Basic/DiagnosticLexKinds.td
index becbd73..c6d26a0 100644
--- a/include/clang/Basic/DiagnosticLexKinds.td
+++ b/include/clang/Basic/DiagnosticLexKinds.td
@@ -228,6 +228,10 @@
 
 def ext_pp_import_directive : Extension<"#import is a language extension">,
   InGroup<DiagGroup<"import-preprocessor-directive-pedantic">>;
+def err_pp_import_directive_ms : Error<
+  "#import of type library is an unsupported Microsoft feature">,
+  InGroup<Microsoft>;
+
 def ext_pp_ident_directive : Extension<"#ident is a language extension">;
 def ext_pp_include_next_directive : Extension<
   "#include_next is a language extension">;
diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h
index 2abf74e..fa9c417 100644
--- a/include/clang/Lex/Preprocessor.h
+++ b/include/clang/Lex/Preprocessor.h
@@ -1250,6 +1250,7 @@
   void HandleIncludeNextDirective(SourceLocation HashLoc, Token &Tok);
   void HandleIncludeMacrosDirective(SourceLocation HashLoc, Token &Tok);
   void HandleImportDirective(SourceLocation HashLoc, Token &Tok);
+  void HandleMicrosoftImportDirective(Token &Tok);
 
   // Macro handling.
   void HandleDefineDirective(Token &Tok);
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index 53bb5c3..3d96e86 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -1484,13 +1484,29 @@
   return HandleIncludeDirective(HashLoc, IncludeNextTok, Lookup);
 }
 
+/// HandleMicrosoftImportDirective - Implements #import for Microsoft Mode
+void Preprocessor::HandleMicrosoftImportDirective(Token &Tok) {
+  // The Microsoft #import directive takes a type library and generates header
+  // files from it, and includes those.  This is beyond the scope of what clang
+  // does, so we ignore it and error out.  However, #import can optionally have
+  // trailing attributes that span multiple lines.  We're going to eat those
+  // so we can continue processing from there.
+  Diag(Tok, diag::err_pp_import_directive_ms );
+
+  // Read tokens until we get to the end of the directive.  Note that the 
+  // directive can be split over multiple lines using the backslash character.
+  DiscardUntilEndOfDirective();
+}
+
 /// HandleImportDirective - Implements #import.
 ///
 void Preprocessor::HandleImportDirective(SourceLocation HashLoc,
                                          Token &ImportTok) {
-  if (!LangOpts.ObjC1)  // #import is standard for ObjC.
+  if (!LangOpts.ObjC1) {  // #import is standard for ObjC.
+    if (LangOpts.MicrosoftMode)
+      return HandleMicrosoftImportDirective(ImportTok);
     Diag(ImportTok, diag::ext_pp_import_directive);
-
+  }
   return HandleIncludeDirective(HashLoc, ImportTok, 0, true);
 }
 
diff --git a/test/Preprocessor/microsoft-import.c b/test/Preprocessor/microsoft-import.c
new file mode 100644
index 0000000..56b5286
--- /dev/null
+++ b/test/Preprocessor/microsoft-import.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -E -fms-compatibility %s 2>&1 | grep 'doh.c:100:2: error: #import of type library is an unsupported Microsoft feature'

+// RUN: %clang_cc1 -E -fms-compatibility %s 2>&1 | grep 'doh.c:200:2: error: #import of type library is an unsupported Microsoft feature'

+// RUN: %clang_cc1 -E -fms-compatibility %s 2>&1 | grep 'doh.c:300:2: error: #import of type library is an unsupported Microsoft feature'

+
+#line 100 "doh.c"

+#import "pp-record.h" // expected-error {{#import of type library is an unsupported Microsoft feature}}
+
+// Test attributes
+#line 200 "doh.c"

+#import "pp-record.h" no_namespace, auto_rename // expected-error {{#import of type library is an unsupported Microsoft feature}}
+
+// This will also fire the "#import of type library is an unsupported Microsoft feature"
+// error, but we can't use -verify because there's no way to put the comment on the proper line

+#line 300 "doh.c"

+#import "pp-record.h" no_namespace \
+                      auto_rename \
+                      auto_search