<div dir="ltr">This change was causing MSan/ASan failures on the sanitizer bots: <a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/28272">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/28272</a><div><br></div><div>I reverted it in r351282.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 15, 2019 at 11:09 AM Haojian Wu 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: hokein<br>
Date: Tue Jan 15 11:05:50 2019<br>
New Revision: 351222<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=351222&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=351222&view=rev</a><br>
Log:<br>
[Tooling] Make clang-tool find libc++ dir on mac when running on a file without compilation database.<br>
<br>
Summary:<br>
This is a regression of r348365.<br>
<br>
When clang-tools run on a file without a complation database (`clang-check /tmp/t.cc`),<br>
we will use fixed compilation database as a fallback. However the actual compiler<br>
path in the fallback complation command is just `clang-tool` which is<br>
insufficient to detect the libc++ dir.<br>
<br>
Reviewers: ilya-biryukov, EricWF<br>
<br>
Reviewed By: ilya-biryukov<br>
<br>
Subscribers: cfe-commits<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D56680" rel="noreferrer" target="_blank">https://reviews.llvm.org/D56680</a><br>
<br>
Added:<br>
    cfe/trunk/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp<br>
Modified:<br>
    cfe/trunk/lib/Tooling/CompilationDatabase.cpp<br>
<br>
Modified: cfe/trunk/lib/Tooling/CompilationDatabase.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CompilationDatabase.cpp?rev=351222&r1=351221&r2=351222&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/CompilationDatabase.cpp?rev=351222&r1=351221&r2=351222&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Tooling/CompilationDatabase.cpp (original)<br>
+++ cfe/trunk/lib/Tooling/CompilationDatabase.cpp Tue Jan 15 11:05:50 2019<br>
@@ -227,6 +227,16 @@ struct FilterUnusedFlags {<br>
   }<br>
 };<br>
<br>
+std::string GetClangToolCommand() {<br>
+  static int Dummy;<br>
+  std::string ClangExecutable =<br>
+      llvm::sys::fs::getMainExecutable("clang", (void *)&Dummy);<br>
+  SmallString<128> ClangToolPath;<br>
+  ClangToolPath = llvm::sys::path::parent_path(ClangExecutable);<br>
+  llvm::sys::path::append(ClangToolPath, "clang-tool");<br>
+  return ClangToolPath.str();<br>
+}<br>
+<br>
 } // namespace<br>
<br>
 /// Strips any positional args and possible argv[0] from a command-line<br>
@@ -266,9 +276,9 @@ static bool stripPositionalArgs(std::vec<br>
       Diagnostics));<br>
   NewDriver->setCheckInputsExist(false);<br>
<br>
-  // This becomes the new argv[0]. The value is actually not important as it<br>
-  // isn't used for invoking Tools.<br>
-  Args.insert(Args.begin(), "clang-tool");<br>
+  // This becomes the new argv[0]. The value is used to detect libc++ include<br>
+  // dirs on Mac, it isn't used for other platforms.<br>
+  Args.insert(Args.begin(), GetClangToolCommand().c_str());<br>
<br>
   // By adding -c, we force the driver to treat compilation as the last phase.<br>
   // It will then issue warnings via Diagnostics about un-used options that<br>
@@ -366,7 +376,7 @@ FixedCompilationDatabase::loadFromFile(S<br>
<br>
 FixedCompilationDatabase::<br>
 FixedCompilationDatabase(Twine Directory, ArrayRef<std::string> CommandLine) {<br>
-  std::vector<std::string> ToolCommandLine(1, "clang-tool");<br>
+  std::vector<std::string> ToolCommandLine(1, GetClangToolCommand());<br>
   ToolCommandLine.insert(ToolCommandLine.end(),<br>
                          CommandLine.begin(), CommandLine.end());<br>
   CompileCommands.emplace_back(Directory, StringRef(),<br>
<br>
Added: cfe/trunk/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp?rev=351222&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp?rev=351222&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp (added)<br>
+++ cfe/trunk/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp Tue Jan 15 11:05:50 2019<br>
@@ -0,0 +1,16 @@<br>
+// Clang on MacOS can find libc++ living beside the installed compiler.<br>
+// This test makes sure our libTooling-based tools emulate this properly with<br>
+// fixed compilation database.<br>
+//<br>
+// RUN: rm -rf %t<br>
+// RUN: mkdir %t<br>
+//<br>
+// Install the mock libc++ (simulates the libc++ directory structure).<br>
+// RUN: cp -r %S/Inputs/mock-libcxx %t/<br>
+//<br>
+// RUN: cp clang-check %t/mock-libcxx/bin/<br>
+// RUN: cp "%s" "%t/test.cpp"<br>
+// RUN: %t/mock-libcxx/bin/clang-check -p "%t" "%t/test.cpp" -- -stdlib=libc++<br>
+<br>
+#include <mock_vector><br>
+vector v;<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="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>