<div dir="ltr">It was related to <a href="https://reviews.llvm.org/D67542" target="_blank">D67542</a> It tried to solve some other problems.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Sep 15, 2019 at 1:40 AM Nico Weber <<a href="mailto:thakis@chromium.org">thakis@chromium.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">This looks similar to <a href="https://reviews.llvm.org/D67542" target="_blank">https://reviews.llvm.org/D67542</a></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Sep 14, 2019 at 1:59 AM Fangrui Song via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Author: maskray<br>
Date: Fri Sep 13 23:01:22 2019<br>
New Revision: 371918<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=371918&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=371918&view=rev</a><br>
Log:<br>
[Driver] Fix multiple bugs related to dependency file options: -M -MM -MD -MMD -MT -MQ<br>
<br>
-M -o test.i => dependency file is test.d, not test.i<br>
-MM -o test.i => dependency file is test.d, not test.i<br>
-M -MMD => bogus warning -Wunused-command-line-argument<br>
-M MT dummy => -w not rendered<br>
<br>
Modified:<br>
cfe/trunk/lib/Driver/Driver.cpp<br>
cfe/trunk/lib/Driver/ToolChains/Clang.cpp<br>
cfe/trunk/test/Driver/m-and-mm.c<br>
<br>
Modified: cfe/trunk/lib/Driver/Driver.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=371918&r1=371917&r2=371918&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=371918&r1=371917&r2=371918&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Driver/Driver.cpp (original)<br>
+++ cfe/trunk/lib/Driver/Driver.cpp Fri Sep 13 23:01:22 2019<br>
@@ -3450,8 +3450,10 @@ Action *Driver::ConstructPhaseAction(<br>
llvm_unreachable("link action invalid here.");<br>
case phases::Preprocess: {<br>
types::ID OutputTy;<br>
- // -{M, MM} alter the output type.<br>
- if (Args.hasArg(options::OPT_M, options::OPT_MM)) {<br>
+ // -M and -MM specify the dependency file name by altering the output type,<br>
+ // -if -MD and -MMD are not specified.<br>
+ if (Args.hasArg(options::OPT_M, options::OPT_MM) &&<br>
+ !Args.hasArg(options::OPT_MD, options::OPT_MMD)) {<br>
OutputTy = types::TY_Dependencies;<br>
} else {<br>
OutputTy = Input->getType();<br>
<br>
Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=371918&r1=371917&r2=371918&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=371918&r1=371917&r2=371918&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)<br>
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Fri Sep 13 23:01:22 2019<br>
@@ -1061,7 +1061,6 @@ void Clang::AddPreprocessingOptions(Comp<br>
ArgStringList &CmdArgs,<br>
const InputInfo &Output,<br>
const InputInfoList &Inputs) const {<br>
- Arg *A;<br>
const bool IsIAMCU = getToolChain().getTriple().isOSIAMCU();<br>
<br>
CheckPreprocessingOptions(D, Args);<br>
@@ -1070,9 +1069,20 @@ void Clang::AddPreprocessingOptions(Comp<br>
Args.AddLastArg(CmdArgs, options::OPT_CC);<br>
<br>
// Handle dependency file generation.<br>
- if ((A = Args.getLastArg(options::OPT_M, options::OPT_MM)) ||<br>
- (A = Args.getLastArg(options::OPT_MD)) ||<br>
- (A = Args.getLastArg(options::OPT_MMD))) {<br>
+ Arg *ArgM = Args.getLastArg(options::OPT_MM);<br>
+ if (!ArgM)<br>
+ ArgM = Args.getLastArg(options::OPT_M);<br>
+ Arg *ArgMD = Args.getLastArg(options::OPT_MMD);<br>
+ if (!ArgMD)<br>
+ ArgMD = Args.getLastArg(options::OPT_MD);<br>
+<br>
+ // -M and -MM imply -w.<br>
+ if (ArgM)<br>
+ CmdArgs.push_back("-w");<br>
+ else<br>
+ ArgM = ArgMD;<br>
+<br>
+ if (ArgM) {<br>
// Determine the output location.<br>
const char *DepFile;<br>
if (Arg *MF = Args.getLastArg(options::OPT_MF)) {<br>
@@ -1080,8 +1090,7 @@ void Clang::AddPreprocessingOptions(Comp<br>
C.addFailureResultFile(DepFile, &JA);<br>
} else if (Output.getType() == types::TY_Dependencies) {<br>
DepFile = Output.getFilename();<br>
- } else if (A->getOption().matches(options::OPT_M) ||<br>
- A->getOption().matches(options::OPT_MM)) {<br>
+ } else if (!ArgMD) {<br>
DepFile = "-";<br>
} else {<br>
DepFile = getDependencyFileName(Args, Inputs);<br>
@@ -1090,8 +1099,22 @@ void Clang::AddPreprocessingOptions(Comp<br>
CmdArgs.push_back("-dependency-file");<br>
CmdArgs.push_back(DepFile);<br>
<br>
+ bool HasTarget = false;<br>
+ for (const Arg *A : Args.filtered(options::OPT_MT, options::OPT_MQ)) {<br>
+ HasTarget = true;<br>
+ A->claim();<br>
+ if (A->getOption().matches(options::OPT_MT)) {<br>
+ A->render(Args, CmdArgs);<br>
+ } else {<br>
+ CmdArgs.push_back("-MT");<br>
+ SmallString<128> Quoted;<br>
+ QuoteTarget(A->getValue(), Quoted);<br>
+ CmdArgs.push_back(Args.MakeArgString(Quoted));<br>
+ }<br>
+ }<br>
+<br>
// Add a default target if one wasn't specified.<br>
- if (!Args.hasArg(options::OPT_MT) && !Args.hasArg(options::OPT_MQ)) {<br>
+ if (!HasTarget) {<br>
const char *DepTarget;<br>
<br>
// If user provided -o, that is the dependency target, except<br>
@@ -1108,17 +1131,14 @@ void Clang::AddPreprocessingOptions(Comp<br>
DepTarget = Args.MakeArgString(llvm::sys::path::filename(P));<br>
}<br>
<br>
- if (!A->getOption().matches(options::OPT_MD) && !A->getOption().matches(options::OPT_MMD)) {<br>
- CmdArgs.push_back("-w");<br>
- }<br>
CmdArgs.push_back("-MT");<br>
SmallString<128> Quoted;<br>
QuoteTarget(DepTarget, Quoted);<br>
CmdArgs.push_back(Args.MakeArgString(Quoted));<br>
}<br>
<br>
- if (A->getOption().matches(options::OPT_M) ||<br>
- A->getOption().matches(options::OPT_MD))<br>
+ if (ArgM->getOption().matches(options::OPT_M) ||<br>
+ ArgM->getOption().matches(options::OPT_MD))<br>
CmdArgs.push_back("-sys-header-deps");<br>
if ((isa<PrecompileJobAction>(JA) &&<br>
!Args.hasArg(options::OPT_fno_module_file_deps)) ||<br>
@@ -1127,8 +1147,8 @@ void Clang::AddPreprocessingOptions(Comp<br>
}<br>
<br>
if (Args.hasArg(options::OPT_MG)) {<br>
- if (!A || A->getOption().matches(options::OPT_MD) ||<br>
- A->getOption().matches(options::OPT_MMD))<br>
+ if (!ArgM || ArgM->getOption().matches(options::OPT_MD) ||<br>
+ ArgM->getOption().matches(options::OPT_MMD))<br>
D.Diag(diag::err_drv_mg_requires_m_or_mm);<br>
CmdArgs.push_back("-MG");<br>
}<br>
@@ -1136,22 +1156,6 @@ void Clang::AddPreprocessingOptions(Comp<br>
Args.AddLastArg(CmdArgs, options::OPT_MP);<br>
Args.AddLastArg(CmdArgs, options::OPT_MV);<br>
<br>
- // Convert all -MQ <target> args to -MT <quoted target><br>
- for (const Arg *A : Args.filtered(options::OPT_MT, options::OPT_MQ)) {<br>
- A->claim();<br>
-<br>
- if (A->getOption().matches(options::OPT_MQ)) {<br>
- CmdArgs.push_back("-MT");<br>
- SmallString<128> Quoted;<br>
- QuoteTarget(A->getValue(), Quoted);<br>
- CmdArgs.push_back(Args.MakeArgString(Quoted));<br>
-<br>
- // -MT flag - no change<br>
- } else {<br>
- A->render(Args, CmdArgs);<br>
- }<br>
- }<br>
-<br>
// Add offload include arguments specific for CUDA. This must happen before<br>
// we -I or -include anything else, because we must pick up the CUDA headers<br>
// from the particular CUDA installation, rather than from e.g.<br>
<br>
Modified: cfe/trunk/test/Driver/m-and-mm.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/m-and-mm.c?rev=371918&r1=371917&r2=371918&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/m-and-mm.c?rev=371918&r1=371917&r2=371918&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Driver/m-and-mm.c (original)<br>
+++ cfe/trunk/test/Driver/m-and-mm.c Fri Sep 13 23:01:22 2019<br>
@@ -1,16 +1,34 @@<br>
-// RUN: %clang -M -MM %s 2>&1 | FileCheck /dev/null --implicit-check-not=warning<br>
+// RUN: %clang -M %s 2>&1 | FileCheck %s --implicit-check-not=warning<br>
+// RUN: %clang -MM %s 2>&1 | FileCheck %s --implicit-check-not=warning<br>
+<br>
+// CHECK: m-and-mm.o:<br>
+// TEST-I: {{.*}}test.i:<br>
+// TEST: {{.*}}test:<br>
<br>
// RUN: mkdir -p %t.dir<br>
+<br>
+/// if -MD and -MMD are not specified, -o specifies the dependency file name.<br>
+// RUN: rm -f %t.dir/test.i<br>
+// RUN: %clang -M %s -o %t.dir/test.i<br>
+// RUN: FileCheck %s < %t.dir/test.i<br>
+// RUN: rm -f %t.dir/test.i<br>
+// RUN: %clang -MM %s -o %t.dir/test.i<br>
+// RUN: FileCheck %s < %t.dir/test.i<br>
+<br>
// RUN: rm -f %t.dir/test.d<br>
// RUN: %clang -fsyntax-only -MD %s -o %t.dir/test.i<br>
-// RUN: test -f %t.dir/test.d<br>
+// RUN: FileCheck --check-prefix=TEST-I %s < %t.dir/test.d<br>
+<br>
+// RUN: rm -f %t.dir/test.d<br>
+// RUN: %clang -M -MD %s -o %t.dir/test.i<br>
+// RUN: FileCheck --check-prefix=TEST-I %s < %t.dir/test.d<br>
<br>
/// If the output file name does not have a suffix, just append `.d`.<br>
// RUN: rm -f %t.dir/test.d<br>
// RUN: %clang -fsyntax-only -MD %s -o %t.dir/test<br>
-// RUN: test -f %t.dir/test.d<br>
+// RUN: FileCheck --check-prefix=TEST %s < %t.dir/test.d<br>
<br>
-#warning "-M and -MM suppresses preprocessing, thus this warning shouldn't show up"<br>
+#warning "-M and -MM suppresses warnings, thus this warning shouldn't show up"<br>
int main(void)<br>
{<br>
return 0;<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">宋方睿</div></div>