<div dir="ltr">Hi Guansong,<div><br></div><div>So this wasn't quite the right way to write this testcase. You really wanted a CHECK/CHECK-NOT line along with the actual commands. You also didn't want to (as you noticed later) depend on full compilation. You can check for this sort of thing in the future by using the -### command line option to get the subcommands that clang -would- invoke if it were actually going to do it.</div><div><br></div><div>I've gone ahead and fixed this thusly:</div><div><div>Committing to <a href="https://llvm.org/svn/llvm-project/cfe/trunk">https://llvm.org/svn/llvm-project/cfe/trunk</a> ...</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>M<span class="Apple-tab-span" style="white-space:pre"> </span>test/Driver/<a href="http://include-default-header.cl">include-default-header.cl</a></div><div>Committed r297917</div></div><div><br></div><div>Thanks!</div><div><br></div><div>-eric</div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Mar 15, 2017 at 2:09 PM Guansong Zhang via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: guansong<br class="gmail_msg">
Date: Wed Mar 15 15:57:11 2017<br class="gmail_msg">
New Revision: 297890<br class="gmail_msg">
<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=297890&view=rev" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project?rev=297890&view=rev</a><br class="gmail_msg">
Log:<br class="gmail_msg">
enable -save-temps with -finclude-defult-header<br class="gmail_msg">
<br class="gmail_msg">
Currently the two flags can not work together.<br class="gmail_msg">
<br class="gmail_msg">
To illustrate the issue, we can have an one line file <a href="http://a.cl" rel="noreferrer" class="gmail_msg" target="_blank">a.cl</a> contains only an empty function<br class="gmail_msg">
<br class="gmail_msg">
cat <a href="http://a.cl" rel="noreferrer" class="gmail_msg" target="_blank">a.cl</a><br class="gmail_msg">
<br class="gmail_msg">
void test(){}<br class="gmail_msg">
<br class="gmail_msg">
Then use<br class="gmail_msg">
<br class="gmail_msg">
clang -v -save-temps -x cl -Xclang -cl-std=CL2.0 -Xclang -finclude-default-header -target amdgcn -S -c <a href="http://a.cl" rel="noreferrer" class="gmail_msg" target="_blank">a.cl</a><br class="gmail_msg">
<br class="gmail_msg">
we will get redefinition errors for various things.<br class="gmail_msg">
<br class="gmail_msg">
The reason is that the -finclude-default-header flag is not meant to be on cc1 command other than the preprocessor.<br class="gmail_msg">
<br class="gmail_msg">
The fix is modeled after the code just below the change to filter the -finclude-default-header flag out when we are not in the preprocess phase.<br class="gmail_msg">
<br class="gmail_msg">
Differential Revision: <a href="https://reviews.llvm.org/D30743" rel="noreferrer" class="gmail_msg" target="_blank">https://reviews.llvm.org/D30743</a><br class="gmail_msg">
<br class="gmail_msg">
Added:<br class="gmail_msg">
cfe/trunk/test/Driver/<a href="http://include-default-header.cl" rel="noreferrer" class="gmail_msg" target="_blank">include-default-header.cl</a><br class="gmail_msg">
Modified:<br class="gmail_msg">
cfe/trunk/lib/Driver/ToolChains/Clang.cpp<br class="gmail_msg">
<br class="gmail_msg">
Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp<br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=297890&r1=297889&r2=297890&view=diff" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=297890&r1=297889&r2=297890&view=diff</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)<br class="gmail_msg">
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Wed Mar 15 15:57:11 2017<br class="gmail_msg">
@@ -4268,7 +4268,19 @@ void Clang::ConstructJob(Compilation &C,<br class="gmail_msg">
<br class="gmail_msg">
// Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option<br class="gmail_msg">
// parser.<br class="gmail_msg">
- Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);<br class="gmail_msg">
+ // -finclude-default-header flag is for preprocessor,<br class="gmail_msg">
+ // do not pass it to other cc1 commands when save-temps is enabled<br class="gmail_msg">
+ if (C.getDriver().isSaveTempsEnabled() &&<br class="gmail_msg">
+ !isa<PreprocessJobAction>(JA)) {<br class="gmail_msg">
+ for (auto Arg : Args.filtered(options::OPT_Xclang)) {<br class="gmail_msg">
+ Arg->claim();<br class="gmail_msg">
+ if (StringRef(Arg->getValue()) != "-finclude-default-header")<br class="gmail_msg">
+ CmdArgs.push_back(Arg->getValue());<br class="gmail_msg">
+ }<br class="gmail_msg">
+ }<br class="gmail_msg">
+ else {<br class="gmail_msg">
+ Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);<br class="gmail_msg">
+ }<br class="gmail_msg">
for (const Arg *A : Args.filtered(options::OPT_mllvm)) {<br class="gmail_msg">
A->claim();<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
Added: cfe/trunk/test/Driver/<a href="http://include-default-header.cl" rel="noreferrer" class="gmail_msg" target="_blank">include-default-header.cl</a><br class="gmail_msg">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/include-default-header.cl?rev=297890&view=auto" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/include-default-header.cl?rev=297890&view=auto</a><br class="gmail_msg">
==============================================================================<br class="gmail_msg">
--- cfe/trunk/test/Driver/<a href="http://include-default-header.cl" rel="noreferrer" class="gmail_msg" target="_blank">include-default-header.cl</a> (added)<br class="gmail_msg">
+++ cfe/trunk/test/Driver/<a href="http://include-default-header.cl" rel="noreferrer" class="gmail_msg" target="_blank">include-default-header.cl</a> Wed Mar 15 15:57:11 2017<br class="gmail_msg">
@@ -0,0 +1,4 @@<br class="gmail_msg">
+// RUN: %clang -v -save-temps -x cl -Xclang -cl-std=CL2.0 -Xclang -finclude-default-header -target amdgcn -S -c %s<br class="gmail_msg">
+<br class="gmail_msg">
+void test() {}<br class="gmail_msg">
+<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
cfe-commits mailing list<br class="gmail_msg">
<a href="mailto:cfe-commits@lists.llvm.org" class="gmail_msg" target="_blank">cfe-commits@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br class="gmail_msg">
</blockquote></div>