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