]> granicus.if.org Git - clang/commitdiff
[modules] Don't write @import in -E output if the current language mode doesn't
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 8 Apr 2016 00:09:53 +0000 (00:09 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 8 Apr 2016 00:09:53 +0000 (00:09 +0000)
support @import; use the form as written instead.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@265756 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/PrintPreprocessedOutput.cpp
lib/Frontend/Rewrite/InclusionRewriter.cpp
test/Modules/preprocess.cpp [new file with mode: 0644]

index 5dd7980d81bfd9316b75b13682b3e09ec18ca3c8..9524b58e3a2b44359589ae77df71d1cfe92125dd 100644 (file)
@@ -326,8 +326,18 @@ void PrintPPOutputPPCallbacks::InclusionDirective(SourceLocation HashLoc,
   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;
index ca8226251fd9c8a46eba516512b883c6fd39f904..b761c34fcbdebf3e8b361425f6ab26b8524ee9c7 100644 (file)
@@ -450,7 +450,9 @@ bool InclusionRewriter::Process(FileID FileId,
               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
diff --git a/test/Modules/preprocess.cpp b/test/Modules/preprocess.cpp
new file mode 100644 (file)
index 0000000..aa28191
--- /dev/null
@@ -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