[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
asukainori added a comment. I'm sorry to disturb. But I found this option is conflict with -flto. e.g. clang-cl -fuse-ld=lld -flto=thin /showFilenames .\test.cpp will output: clang-cl: warning: argument unused during compilation: '/showFilenames' [-Wunused-command-line-argument] Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D52773/new/ https://reviews.llvm.org/D52773 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
This revision was automatically updated to reflect the committed changes. Closed by commit rL344234: clang-cl: Add /showFilenames option (PR31957) (authored by hans, committed by ). Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D52773?vs=168999&id=169178#toc Repository: rL LLVM https://reviews.llvm.org/D52773 Files: cfe/trunk/include/clang/Driver/CLCompatOptions.td cfe/trunk/include/clang/Driver/Job.h cfe/trunk/lib/Driver/Job.cpp cfe/trunk/lib/Driver/ToolChains/Clang.cpp cfe/trunk/test/Driver/cl-showfilenames.c Index: cfe/trunk/include/clang/Driver/Job.h === --- cfe/trunk/include/clang/Driver/Job.h +++ cfe/trunk/include/clang/Driver/Job.h @@ -59,6 +59,9 @@ /// The list of program arguments which are inputs. llvm::opt::ArgStringList InputFilenames; + /// Whether to print the input filenames when executing. + bool PrintInputFilenames = false; + /// Response file name, if this command is set to use one, or nullptr /// otherwise const char *ResponseFile = nullptr; @@ -128,6 +131,9 @@ /// Print a command argument, and optionally quote it. static void printArg(llvm::raw_ostream &OS, StringRef Arg, bool Quote); + + /// Set whether to print the input filenames when executing. + void setPrintInputFilenames(bool P) { PrintInputFilenames = P; } }; /// Like Command, but with a fallback which is executed in case Index: cfe/trunk/include/clang/Driver/CLCompatOptions.td === --- cfe/trunk/include/clang/Driver/CLCompatOptions.td +++ cfe/trunk/include/clang/Driver/CLCompatOptions.td @@ -158,6 +158,10 @@ def _SLASH_showIncludes : CLFlag<"showIncludes">, HelpText<"Print info about included files to stderr">, Alias; +def _SLASH_showFilenames : CLFlag<"showFilenames">, + HelpText<"Print the name of each compiled file">; +def _SLASH_showFilenames_ : CLFlag<"showFilenames-">, + HelpText<"Don't print the name of each compiled file (default)">; def _SLASH_source_charset : CLCompileJoined<"source-charset:">, HelpText<"Source encoding, supports only UTF-8">, Alias; def _SLASH_execution_charset : CLCompileJoined<"execution-charset:">, Index: cfe/trunk/test/Driver/cl-showfilenames.c === --- cfe/trunk/test/Driver/cl-showfilenames.c +++ cfe/trunk/test/Driver/cl-showfilenames.c @@ -0,0 +1,19 @@ +// RUN: %clang_cl /c /showFilenames -- %s 2>&1 | FileCheck -check-prefix=show %s +// RUN: %clang_cl /c /showFilenames -- %s %S/Inputs/wildcard*.c 2>&1 | FileCheck -check-prefix=multiple %s + +// RUN: %clang_cl /c -- %s 2>&1 | FileCheck -check-prefix=noshow %s +// RUN: %clang_cl /c /showFilenames /showFilenames- -- %s 2>&1 | FileCheck -check-prefix=noshow %s + + +#pragma message "Hello" + +// show: cl-showfilenames.c +// show-NEXT: warning: Hello + +// multiple: cl-showfilenames.c +// multiple-NEXT: warning: Hello +// multiple: wildcard1.c +// multiple-NEXT: wildcard2.c + +// noshow: warning: Hello +// noshow-NOT: cl-showfilenames.c Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp === --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp @@ -5067,6 +5067,13 @@ C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs)); } + // Make the compile command echo its inputs for /showFilenames. + if (Output.getType() == types::TY_Object && + Args.hasFlag(options::OPT__SLASH_showFilenames, + options::OPT__SLASH_showFilenames_, false)) { +C.getJobs().getJobs().back()->setPrintInputFilenames(true); + } + if (Arg *A = Args.getLastArg(options::OPT_pg)) if (!shouldUseFramePointer(Args, Triple)) D.Diag(diag::err_drv_argument_not_allowed_with) << "-fomit-frame-pointer" Index: cfe/trunk/lib/Driver/Job.cpp === --- cfe/trunk/lib/Driver/Job.cpp +++ cfe/trunk/lib/Driver/Job.cpp @@ -315,6 +315,12 @@ int Command::Execute(ArrayRef> Redirects, std::string *ErrMsg, bool *ExecutionFailed) const { + if (PrintInputFilenames) { +for (const char *Arg : InputFilenames) + llvm::outs() << llvm::sys::path::filename(Arg) << "\n"; +llvm::outs().flush(); + } + SmallVector Argv; Optional> Env; Index: cfe/trunk/include/clang/Driver/Job.h === --- cfe/trunk/include/clang/Driver/Job.h +++ cfe/trunk/include/clang/Driver/Job.h @@ -59,6 +59,9 @@ /// The list of program arguments which are inputs. llvm::opt::ArgStringList InputFilenames; + /// Whether to print the input filenames when executing. + bool PrintInputFilenames = false; + /// Response file name, if this command is set to use one, or nullptr /// otherwise const char *ResponseFile
[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
hans added inline comments. Comment at: test/Driver/cl-showfilenames.c:7-8 +// multiple: cl-showfilenames.c +// multiple-NEXT: wildcard1.c +// multiple-NEXT: wildcard2.c rnk wrote: > I think it'd be nice to have the test show that diagnostics come out > interleaved between the filenames. You can use `#pragma message` in the input > files or something else to create warnings. Good idea, thanks. https://reviews.llvm.org/D52773 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
rnk accepted this revision. rnk added a comment. lgtm Comment at: lib/Driver/Job.cpp:319 + if (PrintInputFilenames) { +for (const char *Arg : InputFilenames) + llvm::outs() << llvm::sys::path::filename(Arg) << "\n"; Huh, a -cc1 action can have multiple inputs? Go figure. Comment at: test/Driver/cl-showfilenames.c:7-8 +// multiple: cl-showfilenames.c +// multiple-NEXT: wildcard1.c +// multiple-NEXT: wildcard2.c I think it'd be nice to have the test show that diagnostics come out interleaved between the filenames. You can use `#pragma message` in the input files or something else to create warnings. https://reviews.llvm.org/D52773 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
hans updated this revision to Diff 168999. hans added a comment. Here's a version now using cc1 flags, but printing directly from the driver. Please take a look. https://reviews.llvm.org/D52773 Files: include/clang/Driver/CLCompatOptions.td include/clang/Driver/Job.h lib/Driver/Job.cpp lib/Driver/ToolChains/Clang.cpp test/Driver/cl-showfilenames.c Index: test/Driver/cl-showfilenames.c === --- /dev/null +++ test/Driver/cl-showfilenames.c @@ -0,0 +1,8 @@ +// RUN: %clang_cl /c /showFilenames -- %s 2>&1 | FileCheck -check-prefix=show %s +// RUN: %clang_cl /c /showFilenames -- %s %S/Inputs/wildcard*.c 2>&1 | FileCheck -check-prefix=multiple %s + +// show: cl-showfilenames.c + +// multiple: cl-showfilenames.c +// multiple-NEXT: wildcard1.c +// multiple-NEXT: wildcard2.c Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -5066,6 +5066,13 @@ C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs)); } + // Make the compile command echo its inputs for /showFilenames. + if (Output.getType() == types::TY_Object && + Args.hasFlag(options::OPT__SLASH_showFilenames, + options::OPT__SLASH_showFilenames_, false)) { +C.getJobs().getJobs().back()->setPrintInputFilenames(true); + } + if (Arg *A = Args.getLastArg(options::OPT_pg)) if (!shouldUseFramePointer(Args, Triple)) D.Diag(diag::err_drv_argument_not_allowed_with) << "-fomit-frame-pointer" Index: lib/Driver/Job.cpp === --- lib/Driver/Job.cpp +++ lib/Driver/Job.cpp @@ -315,6 +315,11 @@ int Command::Execute(ArrayRef> Redirects, std::string *ErrMsg, bool *ExecutionFailed) const { + if (PrintInputFilenames) { +for (const char *Arg : InputFilenames) + llvm::outs() << llvm::sys::path::filename(Arg) << "\n"; + } + SmallVector Argv; Optional> Env; Index: include/clang/Driver/Job.h === --- include/clang/Driver/Job.h +++ include/clang/Driver/Job.h @@ -59,6 +59,9 @@ /// The list of program arguments which are inputs. llvm::opt::ArgStringList InputFilenames; + /// Whether to print the input filenames when executing. + bool PrintInputFilenames = false; + /// Response file name, if this command is set to use one, or nullptr /// otherwise const char *ResponseFile = nullptr; @@ -128,6 +131,9 @@ /// Print a command argument, and optionally quote it. static void printArg(llvm::raw_ostream &OS, StringRef Arg, bool Quote); + + /// Set whether to print the input filenames when executing. + void setPrintInputFilenames(bool P) { PrintInputFilenames = P; } }; /// Like Command, but with a fallback which is executed in case Index: include/clang/Driver/CLCompatOptions.td === --- include/clang/Driver/CLCompatOptions.td +++ include/clang/Driver/CLCompatOptions.td @@ -158,6 +158,10 @@ def _SLASH_showIncludes : CLFlag<"showIncludes">, HelpText<"Print info about included files to stderr">, Alias; +def _SLASH_showFilenames : CLFlag<"showFilenames">, + HelpText<"Print the name of each compiled file">; +def _SLASH_showFilenames_ : CLFlag<"showFilenames-">, + HelpText<"Don't print the name of each compiled file (default)">; def _SLASH_source_charset : CLCompileJoined<"source-charset:">, HelpText<"Source encoding, supports only UTF-8">, Alias; def _SLASH_execution_charset : CLCompileJoined<"execution-charset:">, Index: test/Driver/cl-showfilenames.c === --- /dev/null +++ test/Driver/cl-showfilenames.c @@ -0,0 +1,8 @@ +// RUN: %clang_cl /c /showFilenames -- %s 2>&1 | FileCheck -check-prefix=show %s +// RUN: %clang_cl /c /showFilenames -- %s %S/Inputs/wildcard*.c 2>&1 | FileCheck -check-prefix=multiple %s + +// show: cl-showfilenames.c + +// multiple: cl-showfilenames.c +// multiple-NEXT: wildcard1.c +// multiple-NEXT: wildcard2.c Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -5066,6 +5066,13 @@ C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs)); } + // Make the compile command echo its inputs for /showFilenames. + if (Output.getType() == types::TY_Object && + Args.hasFlag(options::OPT__SLASH_showFilenames, + options::OPT__SLASH_showFilenames_, false)) { +C.getJobs().getJobs().back()->setPrintInputFilenames(true); + } + if (Arg *A = Args.getLastArg(options::OPT_pg)) if (!shouldUseFramePointer(Args, Triple)) D.Diag(diag::err_drv_argument_not_allowed_with) << "-fomit-frame-pointer" Index: lib/Dr
[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
rnk added a comment. It doesn't address the version skew issue, but my blanket argument against any new environment variable is the existance of things like `_CL_` and `CCC_OVERRIDE_OPTIONS`. You can set any compiler flag you want from the environment, so we should standardize on one way of setting options: flags. https://reviews.llvm.org/D52773 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
zturner added a comment. In https://reviews.llvm.org/D52773#1255491, @thakis wrote: > In https://reviews.llvm.org/D52773#1255093, @zturner wrote: > > > I agree magic environment variables are bad, but without it we don’t > > address the only current actual use we have for this, which is making the > > vs integration print filenames. Detecting compiler version from inside the > > integration is hard > > > We need some solution to this anyhow; e.g. say "this now requires clang 8.0", > or have a clang version dropdown in the UI (which defaults to the latest > release), or something. We can't add an env var for every future flag that > the vs integration might want to use. But it is **very hard** to automatically detect the version from the integration. I tried this and gave up because it was flaky. So sure, we can present a drop-down in the UI, but it could be mismatched, and that would end up creating more problems than it solves. Right now we have exactly 1 use case for showing filenames from clang-cl, and there's no good way to satisfy that use case with a command line option. I agree that we can't add an environment variable for every future flag that the VS integration might want to use, but until that happens, YAGNI. And if and when we do need it, if we manage to come up with a solution to the problem, we can delete support for the environment variable and make it use the new method. https://reviews.llvm.org/D52773 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
thakis added a comment. In https://reviews.llvm.org/D52773#1255093, @zturner wrote: > I agree magic environment variables are bad, but without it we don’t > address the only current actual use we have for this, which is making the > vs integration print filenames. Detecting compiler version from inside the > integration is hard We need some solution to this anyhow; e.g. say "this now requires clang 8.0", or have a clang version dropdown in the UI (which defaults to the latest release), or something. We can't add an env var for every future flag that the vs integration might want to use. https://reviews.llvm.org/D52773 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
zturner added a subscriber: rnk. zturner added a comment. I agree magic environment variables are bad, but without it we don’t address the only current actual use we have for this, which is making the vs integration print filenames. Detecting compiler version from inside the integration is hard, but with an environment variable it’s very easy to solve. I’m not against a flag as the supported way, but I think we should also have some backdoor into this functionality, because if we’re not going to satisfy the only known use case, then maybe it’s better to not even do it at all. https://reviews.llvm.org/D52773 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
I agree magic environment variables are bad, but without it we don’t address the only current actual use we have for this, which is making the vs integration print filenames. Detecting compiler version from inside the integration is hard, but with an environment variable it’s very easy to solve. I’m not against a flag as the supported way, but I think we should also have some backdoor into this functionality, because if we’re not going to satisfy the only known use case, then maybe it’s better to not even do it at all. On Thu, Oct 4, 2018 at 5:13 AM Hans Wennborg via Phabricator < revi...@reviews.llvm.org> wrote: > hans added a comment. > > In https://reviews.llvm.org/D52773#1252584, @zturner wrote: > > > Canyou add a test that demonstrates that multiple input files on the > command line will print all of them? > > > Will do. > > > Also does this really need to be a cc1 arg? Why not just print it in > the driver? > > Yeah, I'll give printing from the driver a try. > > > > > Comment at: include/clang/Driver/CLCompatOptions.td:163 > + HelpText<"Print the name of each compiled file">, > + Alias; > def _SLASH_source_charset : CLCompileJoined<"source-charset:">, > > thakis wrote: > > Can you add /showFilenames- (a no-op) too, for symmetry? > Will do. Actually not just a no-op, but the last option should win. > > > > Comment at: lib/Driver/ToolChains/Clang.cpp:3533-3534 >CmdArgs.push_back(getBaseInputName(Args, Input)); > + if (Arg *A = Args.getLastArg(options::OPT_echo_main_file_name)) > +A->render(Args, CmdArgs); > > > rnk wrote: > > Is a -cc1 flag actually necessary? I was imagining we'd print it in the > driver before we launch the compile job. > Yeah, that's probably better, but will take a bit more work to keep track > of if and what to print in the compile job. I'll give it a try. > > > > Comment at: lib/Frontend/CompilerInvocation.cpp:792 >Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name); > + if (Args.hasArg(OPT_echo_main_file_name)) > +llvm::outs() << Opts.MainFileName << "\n"; > > zturner wrote: > > steveire wrote: > > > zturner wrote: > > > > zturner wrote: > > > > > steveire wrote: > > > > > > hans wrote: > > > > > > > zturner wrote: > > > > > > > > steveire wrote: > > > > > > > > > I'll have to keep a patch around anyway for myself locally > to remove this condition. But maybe someone else will benefit from this. > > > > > > > > > > > > > > > > > > What do you think about changing CMake to so that this is > passed by default when using Clang-CL? > > > > > > > > > > > > > > > > > Do you mean llvms cmake? Or cmake itself? Which generator > are you using? > > > > > > > Can't you just configure your build to pass the flag to > clang-cl? > > > > > > > > > > > > > > I suppose CMake could be made to do that by default when using > clang-cl versions that support the flag and using the MSBuild generator, > but that's for the CMake community to decide I think. Or perhaps our VS > integration could do that, but it gets tricky because it needs to know > whether the flag is supported or not. > > > > > > I mean upstream cmake. My suggestion is independent of the > generator, but it would depend on what Brad decides anyway. I don't intend > to implement it, just report it. > > > > > > > > > > > > I only have one clang but I have multiple buildsystems, and I > don't want to have to add a new flag too all of them. In each toplevel > CMakeLists everyone will need this to make use of the flag: > > > > > > > > > > > > ``` > > > > > > > > > > > > # Have to remember to use "${CMAKE_CXX_SIMULATE_ID}" instead of > > > > > > # Undecorated "CMAKE_CXX_SIMULATE_ID" because there is a > > > > > > # variable named "MSVC" and > > > > > > # the way CMake variables and the "if()" command work requires > this. > > > > > > if (CMAKE_CXX_COMPILER_ID STREQUAL Clang > > > > > > AND ${CMAKE_CXX_SIMULATE_ID} STREQUAL MSVC) > > > > > > # CMake does not have explicit Clang-CL support yet. > > > > > > # It should have a COMPILER_ID for it. > > > > > > set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /showFilename") > > > > > > # etc > > > > > > endif() > > > > > > ``` > > > > > > > > > > > > Upstream CMake can have the logic to add the flag instead. > > > > > But then what if you don’t want it? There would be no way to turn > it off. I don’t think it’s a good fit for cmake > > > > Yes, and actually for this reason i was wondering if we can do it > without a flag at all. What if we just set an magic environment variable? > It handles Stephen’s use case (he can just set it globally), and MSBuild > (we can set it in the extension). > > > > But then what if you don’t want it? There would be no way to turn it > off. > > > > > > Oh, I thought that the last flag would dominate. ie, if cmake > generated `/showFilename` and the user adds `/showFilename-`, then you > would end up with > > > > > >
[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
hans added a comment. In https://reviews.llvm.org/D52773#1252584, @zturner wrote: > Canyou add a test that demonstrates that multiple input files on the command > line will print all of them? Will do. > Also does this really need to be a cc1 arg? Why not just print it in the > driver? Yeah, I'll give printing from the driver a try. Comment at: include/clang/Driver/CLCompatOptions.td:163 + HelpText<"Print the name of each compiled file">, + Alias; def _SLASH_source_charset : CLCompileJoined<"source-charset:">, thakis wrote: > Can you add /showFilenames- (a no-op) too, for symmetry? Will do. Actually not just a no-op, but the last option should win. Comment at: lib/Driver/ToolChains/Clang.cpp:3533-3534 CmdArgs.push_back(getBaseInputName(Args, Input)); + if (Arg *A = Args.getLastArg(options::OPT_echo_main_file_name)) +A->render(Args, CmdArgs); rnk wrote: > Is a -cc1 flag actually necessary? I was imagining we'd print it in the > driver before we launch the compile job. Yeah, that's probably better, but will take a bit more work to keep track of if and what to print in the compile job. I'll give it a try. Comment at: lib/Frontend/CompilerInvocation.cpp:792 Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name); + if (Args.hasArg(OPT_echo_main_file_name)) +llvm::outs() << Opts.MainFileName << "\n"; zturner wrote: > steveire wrote: > > zturner wrote: > > > zturner wrote: > > > > steveire wrote: > > > > > hans wrote: > > > > > > zturner wrote: > > > > > > > steveire wrote: > > > > > > > > I'll have to keep a patch around anyway for myself locally to > > > > > > > > remove this condition. But maybe someone else will benefit from > > > > > > > > this. > > > > > > > > > > > > > > > > What do you think about changing CMake to so that this is > > > > > > > > passed by default when using Clang-CL? > > > > > > > > > > > > > > > Do you mean llvms cmake? Or cmake itself? Which generator are > > > > > > > you using? > > > > > > Can't you just configure your build to pass the flag to clang-cl? > > > > > > > > > > > > I suppose CMake could be made to do that by default when using > > > > > > clang-cl versions that support the flag and using the MSBuild > > > > > > generator, but that's for the CMake community to decide I think. Or > > > > > > perhaps our VS integration could do that, but it gets tricky > > > > > > because it needs to know whether the flag is supported or not. > > > > > I mean upstream cmake. My suggestion is independent of the generator, > > > > > but it would depend on what Brad decides anyway. I don't intend to > > > > > implement it, just report it. > > > > > > > > > > I only have one clang but I have multiple buildsystems, and I don't > > > > > want to have to add a new flag too all of them. In each toplevel > > > > > CMakeLists everyone will need this to make use of the flag: > > > > > > > > > > ``` > > > > > > > > > > # Have to remember to use "${CMAKE_CXX_SIMULATE_ID}" instead of > > > > > # Undecorated "CMAKE_CXX_SIMULATE_ID" because there is a > > > > > # variable named "MSVC" and > > > > > # the way CMake variables and the "if()" command work requires this. > > > > > if (CMAKE_CXX_COMPILER_ID STREQUAL Clang > > > > > AND ${CMAKE_CXX_SIMULATE_ID} STREQUAL MSVC) > > > > > # CMake does not have explicit Clang-CL support yet. > > > > > # It should have a COMPILER_ID for it. > > > > > set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /showFilename") > > > > > # etc > > > > > endif() > > > > > ``` > > > > > > > > > > Upstream CMake can have the logic to add the flag instead. > > > > But then what if you don’t want it? There would be no way to turn it > > > > off. I don’t think it’s a good fit for cmake > > > Yes, and actually for this reason i was wondering if we can do it without > > > a flag at all. What if we just set an magic environment variable? It > > > handles Stephen’s use case (he can just set it globally), and MSBuild (we > > > can set it in the extension). > > > But then what if you don’t want it? There would be no way to turn it off. > > > > Oh, I thought that the last flag would dominate. ie, if cmake generated > > `/showFilename` and the user adds `/showFilename-`, then you would end up > > with > > > > `clang-cl.exe /showFilename /showFilename-` > > > > and it would not be shown. I guess that's not how it works. > > > > Maybe users want to not show it, but not seeing the filename is a > > surprising first-time experience when porting from MSVC to clang-cl using > > Visual Studio. > > > > However, I'll just drop out of the discussion and not make any bug to > > CMake. If anyone else feels strongly, they can do so. > > > > Thanks! > Right, but if we update the VS Integration Extension so that MSBuild > specifies the flag (or sets the environment variable, etc), then any time you > u
[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
zturner added inline comments. Comment at: lib/Frontend/CompilerInvocation.cpp:792 Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name); + if (Args.hasArg(OPT_echo_main_file_name)) +llvm::outs() << Opts.MainFileName << "\n"; steveire wrote: > zturner wrote: > > zturner wrote: > > > steveire wrote: > > > > hans wrote: > > > > > zturner wrote: > > > > > > steveire wrote: > > > > > > > I'll have to keep a patch around anyway for myself locally to > > > > > > > remove this condition. But maybe someone else will benefit from > > > > > > > this. > > > > > > > > > > > > > > What do you think about changing CMake to so that this is passed > > > > > > > by default when using Clang-CL? > > > > > > > > > > > > > Do you mean llvms cmake? Or cmake itself? Which generator are you > > > > > > using? > > > > > Can't you just configure your build to pass the flag to clang-cl? > > > > > > > > > > I suppose CMake could be made to do that by default when using > > > > > clang-cl versions that support the flag and using the MSBuild > > > > > generator, but that's for the CMake community to decide I think. Or > > > > > perhaps our VS integration could do that, but it gets tricky because > > > > > it needs to know whether the flag is supported or not. > > > > I mean upstream cmake. My suggestion is independent of the generator, > > > > but it would depend on what Brad decides anyway. I don't intend to > > > > implement it, just report it. > > > > > > > > I only have one clang but I have multiple buildsystems, and I don't > > > > want to have to add a new flag too all of them. In each toplevel > > > > CMakeLists everyone will need this to make use of the flag: > > > > > > > > ``` > > > > > > > > # Have to remember to use "${CMAKE_CXX_SIMULATE_ID}" instead of > > > > # Undecorated "CMAKE_CXX_SIMULATE_ID" because there is a > > > > # variable named "MSVC" and > > > > # the way CMake variables and the "if()" command work requires this. > > > > if (CMAKE_CXX_COMPILER_ID STREQUAL Clang > > > > AND ${CMAKE_CXX_SIMULATE_ID} STREQUAL MSVC) > > > > # CMake does not have explicit Clang-CL support yet. > > > > # It should have a COMPILER_ID for it. > > > > set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /showFilename") > > > > # etc > > > > endif() > > > > ``` > > > > > > > > Upstream CMake can have the logic to add the flag instead. > > > But then what if you don’t want it? There would be no way to turn it > > > off. I don’t think it’s a good fit for cmake > > Yes, and actually for this reason i was wondering if we can do it without a > > flag at all. What if we just set an magic environment variable? It > > handles Stephen’s use case (he can just set it globally), and MSBuild (we > > can set it in the extension). > > But then what if you don’t want it? There would be no way to turn it off. > > Oh, I thought that the last flag would dominate. ie, if cmake generated > `/showFilename` and the user adds `/showFilename-`, then you would end up > with > > `clang-cl.exe /showFilename /showFilename-` > > and it would not be shown. I guess that's not how it works. > > Maybe users want to not show it, but not seeing the filename is a surprising > first-time experience when porting from MSVC to clang-cl using Visual Studio. > > However, I'll just drop out of the discussion and not make any bug to CMake. > If anyone else feels strongly, they can do so. > > Thanks! Right, but if we update the VS Integration Extension so that MSBuild specifies the flag (or sets the environment variable, etc), then any time you use MSBuild (even if not through the IDE) you would get the output, so to the user it would look no different. https://reviews.llvm.org/D52773 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
steveire added inline comments. Comment at: lib/Frontend/CompilerInvocation.cpp:792 Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name); + if (Args.hasArg(OPT_echo_main_file_name)) +llvm::outs() << Opts.MainFileName << "\n"; zturner wrote: > zturner wrote: > > steveire wrote: > > > hans wrote: > > > > zturner wrote: > > > > > steveire wrote: > > > > > > I'll have to keep a patch around anyway for myself locally to > > > > > > remove this condition. But maybe someone else will benefit from > > > > > > this. > > > > > > > > > > > > What do you think about changing CMake to so that this is passed by > > > > > > default when using Clang-CL? > > > > > > > > > > > Do you mean llvms cmake? Or cmake itself? Which generator are you > > > > > using? > > > > Can't you just configure your build to pass the flag to clang-cl? > > > > > > > > I suppose CMake could be made to do that by default when using clang-cl > > > > versions that support the flag and using the MSBuild generator, but > > > > that's for the CMake community to decide I think. Or perhaps our VS > > > > integration could do that, but it gets tricky because it needs to know > > > > whether the flag is supported or not. > > > I mean upstream cmake. My suggestion is independent of the generator, but > > > it would depend on what Brad decides anyway. I don't intend to implement > > > it, just report it. > > > > > > I only have one clang but I have multiple buildsystems, and I don't want > > > to have to add a new flag too all of them. In each toplevel CMakeLists > > > everyone will need this to make use of the flag: > > > > > > ``` > > > > > > # Have to remember to use "${CMAKE_CXX_SIMULATE_ID}" instead of > > > # Undecorated "CMAKE_CXX_SIMULATE_ID" because there is a > > > # variable named "MSVC" and > > > # the way CMake variables and the "if()" command work requires this. > > > if (CMAKE_CXX_COMPILER_ID STREQUAL Clang > > > AND ${CMAKE_CXX_SIMULATE_ID} STREQUAL MSVC) > > > # CMake does not have explicit Clang-CL support yet. > > > # It should have a COMPILER_ID for it. > > > set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /showFilename") > > > # etc > > > endif() > > > ``` > > > > > > Upstream CMake can have the logic to add the flag instead. > > But then what if you don’t want it? There would be no way to turn it off. > > I don’t think it’s a good fit for cmake > Yes, and actually for this reason i was wondering if we can do it without a > flag at all. What if we just set an magic environment variable? It handles > Stephen’s use case (he can just set it globally), and MSBuild (we can set it > in the extension). > But then what if you don’t want it? There would be no way to turn it off. Oh, I thought that the last flag would dominate. ie, if cmake generated `/showFilename` and the user adds `/showFilename-`, then you would end up with `clang-cl.exe /showFilename /showFilename-` and it would not be shown. I guess that's not how it works. Maybe users want to not show it, but not seeing the filename is a surprising first-time experience when porting from MSVC to clang-cl using Visual Studio. However, I'll just drop out of the discussion and not make any bug to CMake. If anyone else feels strongly, they can do so. Thanks! https://reviews.llvm.org/D52773 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
rnk accepted this revision. rnk added a comment. I support continuing our practice of being silent by default, and not implementing anything like the noisy default version banner printing that MSVC does, or this filename printing. I think setting this flag is something for cmake or the VS integration to do. Only someone who knows something about the progress printing model can set it correctly. Comment at: lib/Driver/ToolChains/Clang.cpp:3533-3534 CmdArgs.push_back(getBaseInputName(Args, Input)); + if (Arg *A = Args.getLastArg(options::OPT_echo_main_file_name)) +A->render(Args, CmdArgs); Is a -cc1 flag actually necessary? I was imagining we'd print it in the driver before we launch the compile job. https://reviews.llvm.org/D52773 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
zturner added inline comments. Comment at: lib/Frontend/CompilerInvocation.cpp:792 Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name); + if (Args.hasArg(OPT_echo_main_file_name)) +llvm::outs() << Opts.MainFileName << "\n"; steveire wrote: > hans wrote: > > zturner wrote: > > > steveire wrote: > > > > I'll have to keep a patch around anyway for myself locally to remove > > > > this condition. But maybe someone else will benefit from this. > > > > > > > > What do you think about changing CMake to so that this is passed by > > > > default when using Clang-CL? > > > > > > > Do you mean llvms cmake? Or cmake itself? Which generator are you using? > > Can't you just configure your build to pass the flag to clang-cl? > > > > I suppose CMake could be made to do that by default when using clang-cl > > versions that support the flag and using the MSBuild generator, but that's > > for the CMake community to decide I think. Or perhaps our VS integration > > could do that, but it gets tricky because it needs to know whether the flag > > is supported or not. > I mean upstream cmake. My suggestion is independent of the generator, but it > would depend on what Brad decides anyway. I don't intend to implement it, > just report it. > > I only have one clang but I have multiple buildsystems, and I don't want to > have to add a new flag too all of them. In each toplevel CMakeLists everyone > will need this to make use of the flag: > > ``` > > # Have to remember to use "${CMAKE_CXX_SIMULATE_ID}" instead of > # Undecorated "CMAKE_CXX_SIMULATE_ID" because there is a > # variable named "MSVC" and > # the way CMake variables and the "if()" command work requires this. > if (CMAKE_CXX_COMPILER_ID STREQUAL Clang > AND ${CMAKE_CXX_SIMULATE_ID} STREQUAL MSVC) > # CMake does not have explicit Clang-CL support yet. > # It should have a COMPILER_ID for it. > set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /showFilename") > # etc > endif() > ``` > > Upstream CMake can have the logic to add the flag instead. But then what if you don’t want it? There would be no way to turn it off. I don’t think it’s a good fit for cmake Comment at: lib/Frontend/CompilerInvocation.cpp:792 Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name); + if (Args.hasArg(OPT_echo_main_file_name)) +llvm::outs() << Opts.MainFileName << "\n"; zturner wrote: > steveire wrote: > > hans wrote: > > > zturner wrote: > > > > steveire wrote: > > > > > I'll have to keep a patch around anyway for myself locally to remove > > > > > this condition. But maybe someone else will benefit from this. > > > > > > > > > > What do you think about changing CMake to so that this is passed by > > > > > default when using Clang-CL? > > > > > > > > > Do you mean llvms cmake? Or cmake itself? Which generator are you > > > > using? > > > Can't you just configure your build to pass the flag to clang-cl? > > > > > > I suppose CMake could be made to do that by default when using clang-cl > > > versions that support the flag and using the MSBuild generator, but > > > that's for the CMake community to decide I think. Or perhaps our VS > > > integration could do that, but it gets tricky because it needs to know > > > whether the flag is supported or not. > > I mean upstream cmake. My suggestion is independent of the generator, but > > it would depend on what Brad decides anyway. I don't intend to implement > > it, just report it. > > > > I only have one clang but I have multiple buildsystems, and I don't want to > > have to add a new flag too all of them. In each toplevel CMakeLists > > everyone will need this to make use of the flag: > > > > ``` > > > > # Have to remember to use "${CMAKE_CXX_SIMULATE_ID}" instead of > > # Undecorated "CMAKE_CXX_SIMULATE_ID" because there is a > > # variable named "MSVC" and > > # the way CMake variables and the "if()" command work requires this. > > if (CMAKE_CXX_COMPILER_ID STREQUAL Clang > > AND ${CMAKE_CXX_SIMULATE_ID} STREQUAL MSVC) > > # CMake does not have explicit Clang-CL support yet. > > # It should have a COMPILER_ID for it. > > set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /showFilename") > > # etc > > endif() > > ``` > > > > Upstream CMake can have the logic to add the flag instead. > But then what if you don’t want it? There would be no way to turn it off. I > don’t think it’s a good fit for cmake Yes, and actually for this reason i was wondering if we can do it without a flag at all. What if we just set an magic environment variable? It handles Stephen’s use case (he can just set it globally), and MSBuild (we can set it in the extension). https://reviews.llvm.org/D52773 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
zturner added a comment. Canyou add a test that demonstrates that multiple input files on the command line will print all of them? Also does this really need to be a cc1 arg? Why not just print it in the driver? https://reviews.llvm.org/D52773 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
thakis accepted this revision. thakis added a comment. This revision is now accepted and ready to land. Looks good. If this is passed and we invoke lld-link, should we give that a similar flag and pass that to lld-link as well? I think link.exe also prints its outputs. Comment at: include/clang/Driver/CLCompatOptions.td:163 + HelpText<"Print the name of each compiled file">, + Alias; def _SLASH_source_charset : CLCompileJoined<"source-charset:">, Can you add /showFilenames- (a no-op) too, for symmetry? https://reviews.llvm.org/D52773 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
steveire added inline comments. Comment at: lib/Frontend/CompilerInvocation.cpp:792 Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name); + if (Args.hasArg(OPT_echo_main_file_name)) +llvm::outs() << Opts.MainFileName << "\n"; hans wrote: > zturner wrote: > > steveire wrote: > > > I'll have to keep a patch around anyway for myself locally to remove this > > > condition. But maybe someone else will benefit from this. > > > > > > What do you think about changing CMake to so that this is passed by > > > default when using Clang-CL? > > > > > Do you mean llvms cmake? Or cmake itself? Which generator are you using? > Can't you just configure your build to pass the flag to clang-cl? > > I suppose CMake could be made to do that by default when using clang-cl > versions that support the flag and using the MSBuild generator, but that's > for the CMake community to decide I think. Or perhaps our VS integration > could do that, but it gets tricky because it needs to know whether the flag > is supported or not. I mean upstream cmake. My suggestion is independent of the generator, but it would depend on what Brad decides anyway. I don't intend to implement it, just report it. I only have one clang but I have multiple buildsystems, and I don't want to have to add a new flag too all of them. In each toplevel CMakeLists everyone will need this to make use of the flag: ``` # Have to remember to use "${CMAKE_CXX_SIMULATE_ID}" instead of # Undecorated "CMAKE_CXX_SIMULATE_ID" because there is a # variable named "MSVC" and # the way CMake variables and the "if()" command work requires this. if (CMAKE_CXX_COMPILER_ID STREQUAL Clang AND ${CMAKE_CXX_SIMULATE_ID} STREQUAL MSVC) # CMake does not have explicit Clang-CL support yet. # It should have a COMPILER_ID for it. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /showFilename") # etc endif() ``` Upstream CMake can have the logic to add the flag instead. https://reviews.llvm.org/D52773 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
hans added inline comments. Comment at: lib/Frontend/CompilerInvocation.cpp:792 Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name); + if (Args.hasArg(OPT_echo_main_file_name)) +llvm::outs() << Opts.MainFileName << "\n"; zturner wrote: > steveire wrote: > > I'll have to keep a patch around anyway for myself locally to remove this > > condition. But maybe someone else will benefit from this. > > > > What do you think about changing CMake to so that this is passed by default > > when using Clang-CL? > > > Do you mean llvms cmake? Or cmake itself? Which generator are you using? Can't you just configure your build to pass the flag to clang-cl? I suppose CMake could be made to do that by default when using clang-cl versions that support the flag and using the MSBuild generator, but that's for the CMake community to decide I think. Or perhaps our VS integration could do that, but it gets tricky because it needs to know whether the flag is supported or not. https://reviews.llvm.org/D52773 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
zturner added inline comments. Comment at: lib/Frontend/CompilerInvocation.cpp:792 Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name); + if (Args.hasArg(OPT_echo_main_file_name)) +llvm::outs() << Opts.MainFileName << "\n"; steveire wrote: > I'll have to keep a patch around anyway for myself locally to remove this > condition. But maybe someone else will benefit from this. > > What do you think about changing CMake to so that this is passed by default > when using Clang-CL? > Do you mean llvms cmake? Or cmake itself? Which generator are you using? https://reviews.llvm.org/D52773 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
steveire added inline comments. Comment at: lib/Frontend/CompilerInvocation.cpp:792 Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name); + if (Args.hasArg(OPT_echo_main_file_name)) +llvm::outs() << Opts.MainFileName << "\n"; I'll have to keep a patch around anyway for myself locally to remove this condition. But maybe someone else will benefit from this. What do you think about changing CMake to so that this is passed by default when using Clang-CL? https://reviews.llvm.org/D52773 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52773: clang-cl: Add /showFilenames option (PR31957)
hans created this revision. hans added reviewers: rnk, thakis, zturner, steveire. Add a /showFilenames option for users who want clang to echo the currently compiled filename. MSVC does this echoing by default, and it's useful for showing progress in build systems that doesn't otherwise provide any progress report, such as MSBuild. https://reviews.llvm.org/D52773 Files: include/clang/Driver/CC1Options.td include/clang/Driver/CLCompatOptions.td lib/Driver/ToolChains/Clang.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/echo-main-filename.c test/Driver/cl-options.c Index: test/Driver/cl-options.c === --- test/Driver/cl-options.c +++ test/Driver/cl-options.c @@ -294,6 +294,9 @@ // RUN: %clang_cl /d1PP -### -- %s 2>&1 | FileCheck -check-prefix=d1PP %s // d1PP: -dD +// RUN: %clang_cl /showFilenames -### -- %s 2>&1 | FileCheck -check-prefix=showFilenames %s +// showFilenames: -echo-main-file-name + // We forward any unrecognized -W diagnostic options to cc1. // RUN: %clang_cl -Wunused-pragmas -### -- %s 2>&1 | FileCheck -check-prefix=WJoined %s // WJoined: "-cc1" Index: test/CodeGen/echo-main-filename.c === --- /dev/null +++ test/CodeGen/echo-main-filename.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -main-file-name foobar -echo-main-file-name %s -emit-llvm -o - | FileCheck %s + +// CHECK: foobar Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -789,6 +789,9 @@ Opts.PreferVectorWidth = Args.getLastArgValue(OPT_mprefer_vector_width_EQ); Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name); + if (Args.hasArg(OPT_echo_main_file_name)) +llvm::outs() << Opts.MainFileName << "\n"; + Opts.VerifyModule = !Args.hasArg(OPT_disable_llvm_verifier); Opts.ControlFlowGuard = Args.hasArg(OPT_cfguard); Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3530,6 +3530,8 @@ // -save-temps. CmdArgs.push_back("-main-file-name"); CmdArgs.push_back(getBaseInputName(Args, Input)); + if (Arg *A = Args.getLastArg(options::OPT_echo_main_file_name)) +A->render(Args, CmdArgs); // Some flags which affect the language (via preprocessor // defines). Index: include/clang/Driver/CLCompatOptions.td === --- include/clang/Driver/CLCompatOptions.td +++ include/clang/Driver/CLCompatOptions.td @@ -158,6 +158,9 @@ def _SLASH_showIncludes : CLFlag<"showIncludes">, HelpText<"Print info about included files to stderr">, Alias; +def _SLASH_showFilenames : CLFlag<"showFilenames">, + HelpText<"Print the name of each compiled file">, + Alias; def _SLASH_source_charset : CLCompileJoined<"source-charset:">, HelpText<"Source encoding, supports only UTF-8">, Alias; def _SLASH_execution_charset : CLCompileJoined<"execution-charset:">, Index: include/clang/Driver/CC1Options.td === --- include/clang/Driver/CC1Options.td +++ include/clang/Driver/CC1Options.td @@ -636,6 +636,8 @@ } +def echo_main_file_name : Flag<["-"], "echo-main-file-name">, + HelpText<"Echo the main file name">; def fblocks_runtime_optional : Flag<["-"], "fblocks-runtime-optional">, HelpText<"Weakly link in the blocks runtime">; def fexternc_nounwind : Flag<["-"], "fexternc-nounwind">, Index: test/Driver/cl-options.c === --- test/Driver/cl-options.c +++ test/Driver/cl-options.c @@ -294,6 +294,9 @@ // RUN: %clang_cl /d1PP -### -- %s 2>&1 | FileCheck -check-prefix=d1PP %s // d1PP: -dD +// RUN: %clang_cl /showFilenames -### -- %s 2>&1 | FileCheck -check-prefix=showFilenames %s +// showFilenames: -echo-main-file-name + // We forward any unrecognized -W diagnostic options to cc1. // RUN: %clang_cl -Wunused-pragmas -### -- %s 2>&1 | FileCheck -check-prefix=WJoined %s // WJoined: "-cc1" Index: test/CodeGen/echo-main-filename.c === --- /dev/null +++ test/CodeGen/echo-main-filename.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -main-file-name foobar -echo-main-file-name %s -emit-llvm -o - | FileCheck %s + +// CHECK: foobar Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -789,6 +789,9 @@ Opts.PreferVectorWidth = Args.getLastArgValue(OPT_mprefer_vector_width_EQ); Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name); + if (Args.hasArg(OPT_echo_main_file_name)) +llvm::outs() << Opts.MainFileName <