From 4207edaf03da28fa917a94b31c5c1eef0e6417dc Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Sun, 18 Mar 2012 03:10:37 +0000 Subject: [PATCH] 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 --- include/clang/Basic/DiagnosticLexKinds.td | 4 ++++ include/clang/Lex/Preprocessor.h | 1 + lib/Lex/PPDirectives.cpp | 20 ++++++++++++++++++-- test/Preprocessor/microsoft-import.c | 17 +++++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 test/Preprocessor/microsoft-import.c diff --git a/include/clang/Basic/DiagnosticLexKinds.td b/include/clang/Basic/DiagnosticLexKinds.td index becbd73198..c6d26a069f 100644 --- a/include/clang/Basic/DiagnosticLexKinds.td +++ b/include/clang/Basic/DiagnosticLexKinds.td @@ -228,6 +228,10 @@ def warn_pp_convert_rhs_to_positive : Warning< def ext_pp_import_directive : Extension<"#import is a language extension">, InGroup>; +def err_pp_import_directive_ms : Error< + "#import of type library is an unsupported Microsoft feature">, + InGroup; + 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 2abf74ed0a..fa9c417af5 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -1250,6 +1250,7 @@ private: 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 53bb5c354e..3d96e86cb2 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -1484,13 +1484,29 @@ void Preprocessor::HandleIncludeNextDirective(SourceLocation HashLoc, 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 0000000000..56b5286761 --- /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 -- 2.40.0