Author: rsmith Date: Thu Apr 7 19:09:53 2016 New Revision: 265756 URL: http://llvm.org/viewvc/llvm-project?rev=265756&view=rev Log: [modules] Don't write @import in -E output if the current language mode doesn't support @import; use the form as written instead.
Added: cfe/trunk/test/Modules/preprocess.cpp Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=265756&r1=265755&r2=265756&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original) +++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Thu Apr 7 19:09:53 2016 @@ -326,8 +326,18 @@ void PrintPPOutputPPCallbacks::Inclusion if (Imported) { startNewLineIfNeeded(); MoveToLine(HashLoc); - OS << "@import " << Imported->getFullModuleName() << ";" - << " /* clang -E: implicit import for \"" << File->getName() << "\" */"; + if (PP.getLangOpts().ObjC2) { + OS << "@import " << Imported->getFullModuleName() << ";" + << " /* clang -E: implicit import for \"" << File->getName() + << "\" */"; + } else { + // FIXME: Preseve whether this was a + // #include/#include_next/#include_macros/#import. + OS << "#include " + << (IsAngled ? '<' : '"') + << FileName + << (IsAngled ? '>' : '"'); + } // Since we want a newline after the @import, but not a #<line>, start a new // line immediately. EmittedTokensOnThisLine = true; Modified: cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp?rev=265756&r1=265755&r2=265756&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp (original) +++ cfe/trunk/lib/Frontend/Rewrite/InclusionRewriter.cpp Thu Apr 7 19:09:53 2016 @@ -450,7 +450,9 @@ bool InclusionRewriter::Process(FileID F WriteLineInfo(FileName, Line - 1, FileType, ""); StringRef LineInfoExtra; SourceLocation Loc = HashToken.getLocation(); - if (const Module *Mod = FindModuleAtLocation(Loc)) + if (const Module *Mod = PP.getLangOpts().ObjC2 + ? FindModuleAtLocation(Loc) + : nullptr) WriteImplicitModuleImport(Mod); else if (const IncludedFile *Inc = FindIncludeAtLocation(Loc)) { // include and recursively process the file Added: cfe/trunk/test/Modules/preprocess.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/preprocess.cpp?rev=265756&view=auto ============================================================================== --- cfe/trunk/test/Modules/preprocess.cpp (added) +++ cfe/trunk/test/Modules/preprocess.cpp Thu Apr 7 19:09:53 2016 @@ -0,0 +1,22 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs -x c++ -E %s | \ +// RUN: FileCheck -strict-whitespace %s --check-prefix=CHECK --check-prefix=CXX +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs -x objective-c -E %s | \ +// RUN: FileCheck -strict-whitespace %s --check-prefix=CHECK --check-prefix=OBJC +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs -x c++ -E -frewrite-includes %s | \ +// RUN: FileCheck -strict-whitespace %s --check-prefix=CHECK --check-prefix=CXX +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs -x objective-c -E -frewrite-includes %s | \ +// RUN: FileCheck -strict-whitespace %s --check-prefix=CHECK --check-prefix=OBJC +#include "dummy.h" +#include "dummy.h" +foo bar baz + +// The weird {{ }} here is to prevent the -frewrite-includes test from matching its own CHECK lines. + +// CXX: #include{{ }}"dummy.h" +// CXX: #include{{ }}"dummy.h" +// CXX: foo bar baz + +// OBJC: @import{{ }}dummy; /* clang +// OBJC: @import{{ }}dummy; /* clang +// OBJC: foo bar baz _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits