summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Driver/Options.td2
-rw-r--r--clang/include/clang/Frontend/PreprocessorOutputOptions.h2
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp1
-rw-r--r--clang/lib/Frontend/PrintPreprocessedOutput.cpp34
-rw-r--r--clang/test/Preprocessor/dump_import.h1
-rw-r--r--clang/test/Preprocessor/dump_import.m6
-rw-r--r--clang/test/Preprocessor/dump_include.c11
-rw-r--r--clang/test/Preprocessor/dump_include.h2
8 files changed, 51 insertions, 8 deletions
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index b74897c756b..602560ee0c5 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -429,6 +429,8 @@ def fno_cuda_approx_transcendentals : Flag<["-"], "fno-cuda-approx-transcendenta
def dA : Flag<["-"], "dA">, Group<d_Group>;
def dD : Flag<["-"], "dD">, Group<d_Group>, Flags<[CC1Option]>,
HelpText<"Print macro definitions in -E mode in addition to normal output">;
+def dI : Flag<["-"], "dI">, Group<d_Group>, Flags<[CC1Option]>,
+ HelpText<"Print include directives in -E mode in addition to normal output">;
def dM : Flag<["-"], "dM">, Group<d_Group>, Flags<[CC1Option]>,
HelpText<"Print macro definitions in -E mode instead of normal output">;
def dead__strip : Flag<["-"], "dead_strip">;
diff --git a/clang/include/clang/Frontend/PreprocessorOutputOptions.h b/clang/include/clang/Frontend/PreprocessorOutputOptions.h
index f86c49039ed..3261b665380 100644
--- a/clang/include/clang/Frontend/PreprocessorOutputOptions.h
+++ b/clang/include/clang/Frontend/PreprocessorOutputOptions.h
@@ -22,6 +22,7 @@ public:
unsigned UseLineDirectives : 1; ///< Use \#line instead of GCC-style \# N.
unsigned ShowMacroComments : 1; ///< Show comments, even in macros.
unsigned ShowMacros : 1; ///< Print macro definitions.
+ unsigned ShowIncludeDirectives : 1; ///< Print includes, imports etc. within preprocessed output.
unsigned RewriteIncludes : 1; ///< Preprocess include directives only.
public:
@@ -32,6 +33,7 @@ public:
UseLineDirectives = 0;
ShowMacroComments = 0;
ShowMacros = 0;
+ ShowIncludeDirectives = 0;
RewriteIncludes = 0;
}
};
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 8588fa37810..571327b806f 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2353,6 +2353,7 @@ static void ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts,
Opts.ShowLineMarkers = !Args.hasArg(OPT_P);
Opts.ShowMacroComments = Args.hasArg(OPT_CC);
Opts.ShowMacros = Args.hasArg(OPT_dM) || Args.hasArg(OPT_dD);
+ Opts.ShowIncludeDirectives = Args.hasArg(OPT_dI);
Opts.RewriteIncludes = Args.hasArg(OPT_frewrite_includes);
Opts.UseLineDirectives = Args.hasArg(OPT_fuse_line_directives);
}
diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
index 77b80e612fb..d48b952ef20 100644
--- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -93,13 +93,16 @@ private:
bool Initialized;
bool DisableLineMarkers;
bool DumpDefines;
+ bool DumpIncludeDirectives;
bool UseLineDirectives;
bool IsFirstFileEntered;
public:
PrintPPOutputPPCallbacks(Preprocessor &pp, raw_ostream &os, bool lineMarkers,
- bool defines, bool UseLineDirectives)
+ bool defines, bool DumpIncludeDirectives,
+ bool UseLineDirectives)
: PP(pp), SM(PP.getSourceManager()), ConcatInfo(PP), OS(os),
DisableLineMarkers(lineMarkers), DumpDefines(defines),
+ DumpIncludeDirectives(DumpIncludeDirectives),
UseLineDirectives(UseLineDirectives) {
CurLine = 0;
CurFilename += "<uninit>";
@@ -320,10 +323,10 @@ void PrintPPOutputPPCallbacks::InclusionDirective(SourceLocation HashLoc,
StringRef SearchPath,
StringRef RelativePath,
const Module *Imported) {
- // When preprocessing, turn implicit imports into @imports.
- // FIXME: This is a stop-gap until a more comprehensive "preprocessing with
- // modules" solution is introduced.
if (Imported) {
+ // When preprocessing, turn implicit imports into @imports.
+ // FIXME: This is a stop-gap until a more comprehensive "preprocessing with
+ // modules" solution is introduced.
startNewLineIfNeeded();
MoveToLine(HashLoc);
if (PP.getLangOpts().ObjC2) {
@@ -331,9 +334,9 @@ void PrintPPOutputPPCallbacks::InclusionDirective(SourceLocation HashLoc,
<< " /* clang -E: implicit import for \"" << File->getName()
<< "\" */";
} else {
- // FIXME: Preseve whether this was a
- // #include/#include_next/#include_macros/#import.
- OS << "#include "
+ const std::string TokenText = PP.getSpelling(IncludeTok);
+ assert(!TokenText.empty());
+ OS << "#" << TokenText << " "
<< (IsAngled ? '<' : '"')
<< FileName
<< (IsAngled ? '>' : '"')
@@ -344,6 +347,20 @@ void PrintPPOutputPPCallbacks::InclusionDirective(SourceLocation HashLoc,
// line immediately.
EmittedTokensOnThisLine = true;
startNewLineIfNeeded();
+ } else {
+ // Not a module import; it's a more vanilla inclusion of some file using one
+ // of: #include, #import, #include_next, #include_macros.
+ if (DumpIncludeDirectives) {
+ startNewLineIfNeeded();
+ MoveToLine(HashLoc);
+ const std::string TokenText = PP.getSpelling(IncludeTok);
+ assert(!TokenText.empty());
+ OS << "#" << TokenText << " "
+ << (IsAngled ? '<' : '"') << FileName << (IsAngled ? '>' : '"')
+ << " /* clang -E -dI */";
+ setEmittedDirectiveOnThisLine();
+ startNewLineIfNeeded();
+ }
}
}
@@ -751,7 +768,8 @@ void clang::DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,
PP.SetCommentRetentionState(Opts.ShowComments, Opts.ShowMacroComments);
PrintPPOutputPPCallbacks *Callbacks = new PrintPPOutputPPCallbacks(
- PP, *OS, !Opts.ShowLineMarkers, Opts.ShowMacros, Opts.UseLineDirectives);
+ PP, *OS, !Opts.ShowLineMarkers, Opts.ShowMacros,
+ Opts.ShowIncludeDirectives, Opts.UseLineDirectives);
// Expand macros in pragmas with -fms-extensions. The assumption is that
// the majority of pragmas in such a file will be Microsoft pragmas.
diff --git a/clang/test/Preprocessor/dump_import.h b/clang/test/Preprocessor/dump_import.h
new file mode 100644
index 00000000000..fded1e52cbb
--- /dev/null
+++ b/clang/test/Preprocessor/dump_import.h
@@ -0,0 +1 @@
+#define DUMP_IMPORT_TESTVAL 1
diff --git a/clang/test/Preprocessor/dump_import.m b/clang/test/Preprocessor/dump_import.m
new file mode 100644
index 00000000000..20424ad507b
--- /dev/null
+++ b/clang/test/Preprocessor/dump_import.m
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -E -dI %s -o - | FileCheck %s
+// CHECK: {{^}}#import "dump_
+
+// See also `dump_include.c` which tests other inclusion cases with `-dI`.
+
+#import "dump_import.h"
diff --git a/clang/test/Preprocessor/dump_include.c b/clang/test/Preprocessor/dump_include.c
new file mode 100644
index 00000000000..b98b5df7b77
--- /dev/null
+++ b/clang/test/Preprocessor/dump_include.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -w -E -dI -isystem %S -imacros %S/dump_include.h %s -o - | FileCheck %s
+// CHECK: {{^}}#__include_macros "/{{([^/]+/)+}}dump_
+// CHECK: {{^}}#include <dump_
+// CHECK: {{^}}#include "dump_
+// CHECK: {{^}}#include_next "dump_
+
+// See also `dump_import.m` which tests the `#import` directive with `-dI`.
+
+#include <dump_include.h>
+#include "dump_include.h"
+#include_next "dump_include.h"
diff --git a/clang/test/Preprocessor/dump_include.h b/clang/test/Preprocessor/dump_include.h
new file mode 100644
index 00000000000..9dafaa50b5c
--- /dev/null
+++ b/clang/test/Preprocessor/dump_include.h
@@ -0,0 +1,2 @@
+#pragma once
+#define DUMP_INCLUDE_TESTVAL 1
OpenPOWER on IntegriCloud