<div dir="ltr">Thanks.<div><br></div><div>-- Sean Silva</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 13, 2015 at 3:33 PM, Paul Robinson <span dir="ltr"><<a href="mailto:paul_robinson@playstation.sony.com" target="_blank">paul_robinson@playstation.sony.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: probinson<br>
Date: Wed May 13 17:33:50 2015<br>
New Revision: 237304<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=237304&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=237304&view=rev</a><br>
Log:<br>
Break \# in a depfile the same way as gcc.<br>
<br>
Backslash followed by # in a filename should have both characters<br>
escaped, if you do it the way GNU Make wants.  GCC doesn't, so we do<br>
it the way GCC does rather than the way GNU Make wants.<br>
<br>
Modified:<br>
    cfe/trunk/lib/Frontend/DependencyFile.cpp<br>
    cfe/trunk/test/Frontend/dependency-gen-escaping.c<br>
<br>
Modified: cfe/trunk/lib/Frontend/DependencyFile.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/DependencyFile.cpp?rev=237304&r1=237303&r2=237304&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/DependencyFile.cpp?rev=237304&r1=237303&r2=237304&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Frontend/DependencyFile.cpp (original)<br>
+++ cfe/trunk/lib/Frontend/DependencyFile.cpp Wed May 13 17:33:50 2015<br>
@@ -310,37 +310,30 @@ void DFGImpl::AddFilename(StringRef File<br>
 /// retry with the unmodified original string.<br>
 ///<br>
 /// GCC tries to accommodate both Make formats by escaping any space or #<br>
-/// characters in the original filename, but not escaping any backslash<br>
-/// characters.  That way, filenames with backslashes will be handled<br>
+/// characters in the original filename, but not escaping backslashes.  The<br>
+/// apparent intent is so that filenames with backslashes will be handled<br>
 /// correctly by BSD Make, and by GNU Make in its fallback mode of using the<br>
 /// unmodified original string; filenames with # or space characters aren't<br>
 /// supported by BSD Make at all, but will be handled correctly by GNU Make<br>
 /// due to the escaping.<br>
 ///<br>
-/// A corner case that GCC does not handle is when the original filename has<br>
-/// a backslash immediately followed by # or space. It will therefore take a<br>
-/// dependency from a directive such as<br>
-///     #include "a\#b.h"<br>
+/// A corner case that GCC gets only partly right is when the original filename<br>
+/// has a backslash immediately followed by space or #.  GNU Make would expect<br>
+/// this backslash to be escaped; however GCC escapes the original backslash<br>
+/// only when followed by space, not #.  It will therefore take a dependency<br>
+/// from a directive such as<br>
+///     #include "a\ b\#c.h"<br>
 /// and emit it as<br>
-///     a\\#b.h<br>
+///     a\\\ b\\#c.h<br>
 /// which GNU Make will interpret as<br>
-///     a\<br>
+///     a\ b\<br>
 /// followed by a comment. Failing to find this file, it will fall back to the<br>
-/// original string, and look for<br>
-///     a\\#b.h<br>
-/// which probably doesn't exist either; in any case it won't find<br>
-///     a\#b.h<br>
+/// original string, which probably doesn't exist either; in any case it won't<br>
+/// find<br>
+///     a\ b\#c.h<br>
 /// which is the actual filename specified by the include directive.<br>
 ///<br>
-/// Clang escapes space, # and $ like GCC does, but also handles the case of<br>
-/// backslash immediately preceding space or # by doubling those backslashes.<br>
-/// This means Clang will emit the dependency from<br>
-///     #include "a\#b.h"<br>
-/// as<br>
-///     a\\\#b.h<br>
-/// which GNU Make will un-escape into<br>
-///     a\#b.h<br>
-/// which is the correct original filename.<br>
+/// Clang does what GCC does, rather than what GNU Make expects.<br>
 ///<br>
 /// NMake/Jom has a different set of scary characters, but wraps filespecs in<br>
 /// double-quotes to avoid misinterpreting them; see<br>
@@ -359,8 +352,11 @@ static void PrintFilename(raw_ostream &O<br>
       OS << Filename;<br>
     return;<br>
   }<br>
+  assert(OutputFormat == DependencyOutputFormat::Make);<br>
   for (unsigned i = 0, e = Filename.size(); i != e; ++i) {<br>
-    if (Filename[i] == ' ' || Filename[i] == '#') {<br>
+    if (Filename[i] == '#') // Handle '#' the broken gcc way.<br>
+      OS << '\\';<br>
+    else if (Filename[i] == ' ') { // Handle space correctly.<br>
       OS << '\\';<br>
       unsigned j = i;<br>
       while (j > 0 && Filename[--j] == '\\')<br>
<br>
Modified: cfe/trunk/test/Frontend/dependency-gen-escaping.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/dependency-gen-escaping.c?rev=237304&r1=237303&r2=237304&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/dependency-gen-escaping.c?rev=237304&r1=237303&r2=237304&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Frontend/dependency-gen-escaping.c (original)<br>
+++ cfe/trunk/test/Frontend/dependency-gen-escaping.c Wed May 13 17:33:50 2015<br>
@@ -17,9 +17,10 @@<br>
 #include "##.h"<br>
 #include "normal.h"<br>
<br>
-// Backslash followed by # or space is handled differently than GCC does,<br>
-// because GCC doesn't emit this obscure corner case the way GNU Make wants it.<br>
-// CHECK: a\b\\\#c\\\ d.h<br>
+// Backslash followed by # or space should escape both characters, because<br>
+// that's what GNU Make wants.  GCC does the right thing with space, but not<br>
+// #, so Clang does too. (There should be 3 backslashes before the #.)<br>
+// CHECK: a\b\\#c\\\ d.h<br>
 // These combinations are just another case for NMAKE.<br>
 // NMAKE: "a\b\#c\ d.h"<br>
<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" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>