[cfe-commits] r153009 - in /cfe/trunk: include/clang/Basic/DiagnosticLexKinds.td include/clang/Lex/Preprocessor.h lib/Lex/PPDirectives.cpp test/Preprocessor/microsoft-import.c
Aaron Ballman
aaron at aaronballman.com
Sat Mar 17 20:10:37 PDT 2012
Author: aaronballman
Date: Sat Mar 17 22:10:37 2012
New Revision: 153009
URL: http://llvm.org/viewvc/llvm-project?rev=153009&view=rev
Log:
Turns #import in MS Mode into an error.
Added:
cfe/trunk/test/Preprocessor/microsoft-import.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Lex/PPDirectives.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=153009&r1=153008&r2=153009&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Sat Mar 17 22:10:37 2012
@@ -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">;
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=153009&r1=153008&r2=153009&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Sat Mar 17 22:10:37 2012
@@ -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);
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=153009&r1=153008&r2=153009&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Sat Mar 17 22:10:37 2012
@@ -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);
}
Added: cfe/trunk/test/Preprocessor/microsoft-import.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/microsoft-import.c?rev=153009&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/microsoft-import.c (added)
+++ cfe/trunk/test/Preprocessor/microsoft-import.c Sat Mar 17 22:10:37 2012
@@ -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
More information about the cfe-commits
mailing list