As reported in PR 13851, clang (trunk r163208) seems to ignore any -MF
option that is used in combination with -E -M or -E -MM.  For example:

  $ clang -E -MM -MF .depend helloworld.c
  clang: warning: argument unused during compilation: '-MF .depend'

and no dependency file is generated, the dependency information is
dumped to standard output instead.

It does work when also compiling, e.g if -MD or -MMD is used:

  $ clang -MMD -MF .depend -c helloworld.c
  $ cat .depend
  helloworld.o: helloworld.c

Looking at Clang::AddPreprocessingOptions() in lib/Driver/Tools.cpp, it
seems the check for a -MF option is done too late: if dependency output
is requested in any way, the DepFile is always the default filename,
which is standard output if -E is used.

I propose the attached patch to fix this.

-Dimitry
Index: tools/clang/lib/Driver/Tools.cpp
===================================================================
--- tools/clang/lib/Driver/Tools.cpp	(revision 163208)
+++ tools/clang/lib/Driver/Tools.cpp	(working copy)
@@ -219,11 +219,11 @@ void Clang::AddPreprocessingOptions(Compilation &C
       (A = Args.getLastArg(options::OPT_MMD))) {
     // Determine the output location.
     const char *DepFile;
-    if (Output.getType() == types::TY_Dependencies) {
-      DepFile = Output.getFilename();
-    } else if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
+    if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
       DepFile = MF->getValue(Args);
       C.addFailureResultFile(DepFile);
+    } else if (Output.getType() == types::TY_Dependencies) {
+      DepFile = Output.getFilename();
     } else if (A->getOption().matches(options::OPT_M) ||
                A->getOption().matches(options::OPT_MM)) {
       DepFile = "-";
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to