<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Aug 8, 2013 at 8:32 PM, Hans Wennborg <span dir="ltr"><<a href="mailto:hans@hanshq.net" target="_blank">hans@hanshq.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: hans<br>
Date: Thu Aug 8 19:32:23 2013<br>
New Revision: 188037<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=188037&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=188037&view=rev</a><br>
Log:<br>
clang-cl: Support /showIncludes<br>
<br>
This option prints information about #included files to stderr. Clang could<br>
already do it, this patch just teaches the existing code about the /showIncludes<br>
style and adds the flag.<br>
<br>
Differential Revision: <a href="http://llvm-reviews.chandlerc.com/D1333" rel="noreferrer" target="_blank">http://llvm-reviews.chandlerc.com/D1333</a><br>
<br>
Modified:<br>
cfe/trunk/include/clang/Driver/CC1Options.td<br>
cfe/trunk/include/clang/Driver/CLCompatOptions.td<br>
cfe/trunk/include/clang/Driver/Options.td<br>
cfe/trunk/include/clang/Frontend/DependencyOutputOptions.h<br>
cfe/trunk/include/clang/Frontend/Utils.h<br>
cfe/trunk/lib/Driver/Tools.cpp<br>
cfe/trunk/lib/Frontend/CompilerInstance.cpp<br>
cfe/trunk/lib/Frontend/CompilerInvocation.cpp<br>
cfe/trunk/lib/Frontend/HeaderIncludeGen.cpp<br>
cfe/trunk/test/Driver/cl-options.c<br>
cfe/trunk/test/Frontend/print-header-includes.c<br>
<br>
Modified: cfe/trunk/include/clang/Driver/CC1Options.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=188037&r1=188036&r2=188037&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=188037&r1=188036&r2=188037&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)<br>
+++ cfe/trunk/include/clang/Driver/CC1Options.td Thu Aug 8 19:32:23 2013<br>
@@ -221,6 +221,8 @@ def sys_header_deps : Flag<["-"], "sys-h<br>
HelpText<"Include system headers in dependency output">;<br>
def header_include_file : Separate<["-"], "header-include-file">,<br>
HelpText<"Filename (or -) to write header include output to">;<br>
+def show_includes : Flag<["--"], "show-includes">,<br>
+ HelpText<"Print cl.exe style /showIncludes to stderr">;<br>
<br>
//===----------------------------------------------------------------------===//<br>
// Diagnostic Options<br>
<br>
Modified: cfe/trunk/include/clang/Driver/CLCompatOptions.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CLCompatOptions.td?rev=188037&r1=188036&r2=188037&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CLCompatOptions.td?rev=188037&r1=188036&r2=188037&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Driver/CLCompatOptions.td (original)<br>
+++ cfe/trunk/include/clang/Driver/CLCompatOptions.td Thu Aug 8 19:32:23 2013<br>
@@ -68,6 +68,9 @@ def _SLASH_Oy_ : CLFlag<"Oy-">, HelpText<br>
def _SLASH_P : CLFlag<"P">, HelpText<"Only run the preprocessor">, Alias<E>;<br>
def _SLASH_QUESTION : CLFlag<"?">, Alias<help>,<br>
HelpText<"Display available options">;<br>
+def _SLASH_showIncludes : CLFlag<"showIncludes">,<br>
+ HelpText<"Print info about included files to stderr">,<br>
+ Alias<show_includes>;<br>
def _SLASH_U : CLJoinedOrSeparate<"U">, HelpText<"Undefine macro">,<br>
MetaVarName<"<macro>">, Alias<U>;<br>
def _SLASH_W0 : CLFlag<"W0">, HelpText<"Disable all warnings">, Alias<w>;<br>
@@ -130,7 +133,6 @@ def _SLASH_Gy : CLFlag<"Gy">;<br>
def _SLASH_Gy_ : CLFlag<"Gy-">;<br>
def _SLASH_GZ : CLFlag<"GZ">;<br>
def _SLASH_RTC : CLJoined<"RTC">;<br>
-def _SLASH_showIncludes : CLJoined<"showIncludes">;<br>
def _SLASH_w : CLJoined<"w">;<br>
def _SLASH_Za : CLFlag<"Za">;<br>
def _SLASH_Zc : CLJoined<"Zc:">;<br>
<br>
Modified: cfe/trunk/include/clang/Driver/Options.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=188037&r1=188036&r2=188037&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=188037&r1=188036&r2=188037&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Driver/Options.td (original)<br>
+++ cfe/trunk/include/clang/Driver/Options.td Thu Aug 8 19:32:23 2013<br>
@@ -1333,6 +1333,6 @@ def Z_reserved_lib_stdcxx : Flag<["-"],<br>
def Z_reserved_lib_cckext : Flag<["-"], "Z-reserved-lib-cckext">,<br>
Flags<[LinkerInput, NoArgumentUnused, Unsupported]>, Group<reserved_lib_Group>;<br>
<br>
-include "CLCompatOptions.td"<br>
-<br>
include "CC1Options.td"<br>
+<br>
+include "CLCompatOptions.td"<br>
<br>
Modified: cfe/trunk/include/clang/Frontend/DependencyOutputOptions.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/DependencyOutputOptions.h?rev=188037&r1=188036&r2=188037&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/DependencyOutputOptions.h?rev=188037&r1=188036&r2=188037&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Frontend/DependencyOutputOptions.h (original)<br>
+++ cfe/trunk/include/clang/Frontend/DependencyOutputOptions.h Thu Aug 8 19:32:23 2013<br>
@@ -25,6 +25,7 @@ public:<br>
/// dependency, which can avoid some 'make'<br>
/// problems.<br>
unsigned AddMissingHeaderDeps : 1; ///< Add missing headers to dependency list<br>
+ unsigned PrintShowIncludes : 1; ///< Print cl.exe style /showIncludes info.<br>
<br>
/// The file to write dependency output to.<br>
std::string OutputFile;<br>
@@ -48,6 +49,7 @@ public:<br>
ShowHeaderIncludes = 0;<br>
UsePhonyTargets = 0;<br>
AddMissingHeaderDeps = 0;<br>
+ PrintShowIncludes = 0;<br>
}<br>
};<br>
<br>
<br>
Modified: cfe/trunk/include/clang/Frontend/Utils.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/Utils.h?rev=188037&r1=188036&r2=188037&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/Utils.h?rev=188037&r1=188036&r2=188037&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Frontend/Utils.h (original)<br>
+++ cfe/trunk/include/clang/Frontend/Utils.h Thu Aug 8 19:32:23 2013<br>
@@ -91,9 +91,11 @@ void AttachDependencyFileGen(Preprocesso<br>
/// the default behavior used by -H.<br>
/// \param OutputPath - If non-empty, a path to write the header include<br>
/// information to, instead of writing to stderr.<br>
+/// \param ShowDepth - Whether to indent to show the nesting of the includes.<br>
+/// \param MSStyle - Whether to print in cl.exe /showIncludes style.<br>
void AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders = false,<br>
StringRef OutputPath = "",<br>
- bool ShowDepth = true);<br>
+ bool ShowDepth = true, bool MSStyle = false);<br>
<br>
/// CacheTokens - Cache tokens for use with PCH. Note that this requires<br>
/// a seekable stream.<br>
<br>
Modified: cfe/trunk/lib/Driver/Tools.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=188037&r1=188036&r2=188037&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=188037&r1=188036&r2=188037&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Driver/Tools.cpp (original)<br>
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Aug 8 19:32:23 2013<br>
@@ -3727,6 +3727,9 @@ void Clang::AddClangCLArgs(const ArgList<br>
// FIXME: Make this default for the win32 triple.<br>
CmdArgs.push_back("-cxx-abi");<br>
CmdArgs.push_back("microsoft");<br>
+<br>
+ if (Arg *A = Args.getLastArg(options::OPT_show_includes))<br>
+ A->render(Args, CmdArgs);<br>
}<br>
<br>
void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,<br>
<br>
Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=188037&r1=188036&r2=188037&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=188037&r1=188036&r2=188037&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)<br>
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Thu Aug 8 19:32:23 2013<br>
@@ -259,7 +259,7 @@ void CompilerInstance::createPreprocesso<br>
AttachDependencyGraphGen(*PP, DepOpts.DOTOutputFile,<br>
getHeaderSearchOpts().Sysroot);<br>
<br>
-<br>
+<br>
// Handle generating header include information, if requested.<br>
if (DepOpts.ShowHeaderIncludes)<br>
AttachHeaderIncludeGen(*PP);<br>
@@ -270,6 +270,11 @@ void CompilerInstance::createPreprocesso<br>
AttachHeaderIncludeGen(*PP, /*ShowAllHeaders=*/true, OutputPath,<br>
/*ShowDepth=*/false);<br>
}<br>
+<br>
+ if (DepOpts.PrintShowIncludes) {<br>
+ AttachHeaderIncludeGen(*PP, /*ShowAllHeaders=*/false, /*OutputPath=*/"",<br>
+ /*ShowDepth=*/true, /*MSStyle=*/true);<br>
+ }<br>
}<br>
<br>
// ASTContext<br>
<br>
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=188037&r1=188036&r2=188037&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=188037&r1=188036&r2=188037&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)<br>
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu Aug 8 19:32:23 2013<br>
@@ -518,6 +518,7 @@ static void ParseDependencyOutputArgs(De<br>
Opts.ShowHeaderIncludes = Args.hasArg(OPT_H);<br>
Opts.HeaderIncludeOutputFile = Args.getLastArgValue(OPT_header_include_file);<br>
Opts.AddMissingHeaderDeps = Args.hasArg(OPT_MG);<br>
+ Opts.PrintShowIncludes = Args.hasArg(OPT_show_includes);<br>
Opts.DOTOutputFile = Args.getLastArgValue(OPT_dependency_dot);<br>
}<br>
<br>
<br>
Modified: cfe/trunk/lib/Frontend/HeaderIncludeGen.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/HeaderIncludeGen.cpp?rev=188037&r1=188036&r2=188037&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/HeaderIncludeGen.cpp?rev=188037&r1=188036&r2=188037&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Frontend/HeaderIncludeGen.cpp (original)<br>
+++ cfe/trunk/lib/Frontend/HeaderIncludeGen.cpp Thu Aug 8 19:32:23 2013<br>
@@ -24,15 +24,16 @@ class HeaderIncludesCallback : public PP<br>
bool OwnsOutputFile;<br>
bool ShowAllHeaders;<br>
bool ShowDepth;<br>
+ bool MSStyle;<br>
<br>
public:<br>
HeaderIncludesCallback(const Preprocessor *PP, bool ShowAllHeaders_,<br>
raw_ostream *OutputFile_, bool OwnsOutputFile_,<br>
- bool ShowDepth_)<br>
+ bool ShowDepth_, bool MSStyle_)<br>
: SM(PP->getSourceManager()), OutputFile(OutputFile_),<br>
CurrentIncludeDepth(0), HasProcessedPredefines(false),<br>
OwnsOutputFile(OwnsOutputFile_), ShowAllHeaders(ShowAllHeaders_),<br>
- ShowDepth(ShowDepth_) {}<br>
+ ShowDepth(ShowDepth_), MSStyle(MSStyle_) {}<br>
<br>
~HeaderIncludesCallback() {<br>
if (OwnsOutputFile)<br>
@@ -46,7 +47,8 @@ public:<br>
}<br>
<br>
void clang::AttachHeaderIncludeGen(Preprocessor &PP, bool ShowAllHeaders,<br>
- StringRef OutputPath, bool ShowDepth) {<br>
+ StringRef OutputPath, bool ShowDepth,<br>
+ bool MSStyle) {<br>
raw_ostream *OutputFile = &llvm::errs();<br>
bool OwnsOutputFile = false;<br>
<br>
@@ -69,7 +71,7 @@ void clang::AttachHeaderIncludeGen(Prepr<br>
<br>
PP.addPPCallbacks(new HeaderIncludesCallback(&PP, ShowAllHeaders,<br>
OutputFile, OwnsOutputFile,<br>
- ShowDepth));<br>
+ ShowDepth, MSStyle));<br>
}<br>
<br>
void HeaderIncludesCallback::FileChanged(SourceLocation Loc,<br>
@@ -109,14 +111,20 @@ void HeaderIncludesCallback::FileChanged<br>
if (ShowHeader && Reason == PPCallbacks::EnterFile) {<br>
// Write to a temporary string to avoid unnecessary flushing on errs().<br>
SmallString<512> Filename(UserLoc.getFilename());<br>
- Lexer::Stringify(Filename);<br>
+ if (!MSStyle)<br>
+ Lexer::Stringify(Filename);<br>
<br>
SmallString<256> Msg;<br>
+ if (MSStyle)<br>
+ Msg += "Note: including file:";<br>
+<br>
if (ShowDepth) {<br>
// The main source file is at depth 1, so skip one dot.<br>
for (unsigned i = 1; i != CurrentIncludeDepth; ++i)<br>
- Msg += '.';<br>
- Msg += ' ';<br>
+ Msg += MSStyle ? ' ' : '.';<br>
+<br>
+ if (!MSStyle)<br>
+ Msg += ' ';<br>
}<br>
Msg += Filename;<br>
Msg += '\n';<br>
<br>
Modified: cfe/trunk/test/Driver/cl-options.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-options.c?rev=188037&r1=188036&r2=188037&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-options.c?rev=188037&r1=188036&r2=188037&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Driver/cl-options.c (original)<br>
+++ cfe/trunk/test/Driver/cl-options.c Thu Aug 8 19:32:23 2013<br>
@@ -59,6 +59,9 @@<br>
// RUN: %clang_cl /P -### -- %s 2>&1 | FileCheck -check-prefix=P %s<br>
// P: -E<br>
<br>
+// RUN: %clang_cl /showIncludes -### -- %s 2>&1 | FileCheck -check-prefix=showIncludes %s<br>
+// showIncludes: --show-includes<br>
+<br>
// RUN: %clang_cl /Umymacro -### -- %s 2>&1 | FileCheck -check-prefix=U %s<br>
// RUN: %clang_cl /U mymacro -### -- %s 2>&1 | FileCheck -check-prefix=U %s<br>
// U: "-U" "mymacro"<br>
@@ -97,4 +100,4 @@<br>
// RUN: %clang_cl /Zs /EHsc /Fdfoo /fp:precise /Gd /GL /GL- -- %s 2>&1<br>
// RUN: %clang_cl /Zs /Gm /Gm- /GS /Gy /Gy- /GZ -- %s 2>&1<br>
// RUN: %clang_cl /Zs /RTC1 /wfoo /Zc:wchar_t- -- %s 2>&1<br>
-// RUN: %clang_cl /Zs /ZI /Zi /showIncludes -- %s 2>&1<br>
+// RUN: %clang_cl /Zs /ZI /Zi -- %s 2>&1<br>
<br>
Modified: cfe/trunk/test/Frontend/print-header-includes.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/print-header-includes.c?rev=188037&r1=188036&r2=188037&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/print-header-includes.c?rev=188037&r1=188036&r2=188037&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Frontend/print-header-includes.c (original)<br>
+++ cfe/trunk/test/Frontend/print-header-includes.c Thu Aug 8 19:32:23 2013<br>
@@ -5,4 +5,11 @@<br>
// CHECK: . {{.*test.h}}<br>
// CHECK: .. {{.*test2.h}}<br>
<br>
+// RUN: %clang_cc1 -include Inputs/test3.h -E --show-includes -o %t.out %s 2> %t.err<br>
+// RUN: FileCheck --check-prefix=MS < %t.err %s<br>
+// MS-NOT: test3.h<br></blockquote><div><br></div><div><div style="font-size:12.8px">Do you remember why this is a -NOT? From what I can tell, `cl /c empty.cc /FItest.h /showIncludes` does print a Note line for test.h. I thought that was a bug, but when I wrote a fix I noticed that we have this test that explicitly checks that /FI arguments are omitted from /showIncludes output.</div><div class="" style="font-size:12.8px"></div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+// MS: Note: including file: {{.*test.h}}<br>
+// MS: Note: including file: {{.*test2.h}}<br>
+// MS-NOT: Note<br>
+<br>
#include "Inputs/test.h"<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>