aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2018-12-05 14:24:14 +0000
committerIlya Biryukov <ibiryukov@google.com>2018-12-05 14:24:14 +0000
commit239d821f087ecadf2db0242020c588eb5e15bdb3 (patch)
tree335b91fa1aa6dabcc0b8cf338fdca832ced63a35
parent09945033ddba820d98555acfa54689598bce4dae (diff)
Move detection of libc++ include dirs to Driver on MacOS
Summary: The intention is to make the tools replaying compilations from 'compile_commands.json' (clang-tidy, clangd, etc.) find the same standard library as the original compiler specified in 'compile_commands.json'. Previously, the library detection logic was in the frontend (InitHeaderSearch.cpp) and relied on the value of resource dir as an approximation of the compiler install dir. The new logic uses the actual compiler install dir and is performed in the driver. This is consistent with the C++ standard library detection on other platforms and allows to override the resource dir in the tools using the compile_commands.json without altering the standard library detection mechanism. The tools have to override the resource dir to make sure they use a consistent version of the builtin headers. There is still logic in InitHeaderSearch that attemps to add the absolute includes for the the C++ standard library, so we keep passing the -stdlib=libc++ from the driver to the frontend via cc1 args to avoid breaking that. In the long run, we should move this logic to the driver too, but it could potentially break the library detection on other systems, so we don't tackle it in this patch to keep its scope manageable. This is a second attempt to fix the issue, first one was commited in r346652 and reverted in r346675. The original fix relied on an ad-hoc propagation (bypassing the cc1 flags) of the install dir from the driver to the frontend's HeaderSearchOptions. Unsurpisingly, the propagation was incomplete, it broke the libc++ detection in clang itself, which caused LLDB tests to break. The LLDB tests pass with new fix. Reviewers: JDevlieghere, arphaman, EricWF Reviewed By: arphaman Subscribers: mclow.lists, ldionne, dexonsmith, ioeric, christof, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D54630 git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@348365 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--test/clang-tidy/Inputs/mock-libcxx/include/c++/v1/mock_vector2
-rw-r--r--test/clang-tidy/clang-tidy-mac-libcxx.cpp17
2 files changed, 19 insertions, 0 deletions
diff --git a/test/clang-tidy/Inputs/mock-libcxx/include/c++/v1/mock_vector b/test/clang-tidy/Inputs/mock-libcxx/include/c++/v1/mock_vector
new file mode 100644
index 00000000..35395267
--- /dev/null
+++ b/test/clang-tidy/Inputs/mock-libcxx/include/c++/v1/mock_vector
@@ -0,0 +1,2 @@
+class vector {};
+typedef vector* vector_ptr;
diff --git a/test/clang-tidy/clang-tidy-mac-libcxx.cpp b/test/clang-tidy/clang-tidy-mac-libcxx.cpp
new file mode 100644
index 00000000..153a5d6e
--- /dev/null
+++ b/test/clang-tidy/clang-tidy-mac-libcxx.cpp
@@ -0,0 +1,17 @@
+// Clang on MacOS can find libc++ living beside the installed compiler.
+// This test makes sure clang-tidy emulates this properly.
+//
+// RUN: rm -rf %t
+// RUN: mkdir %t
+//
+// Install the mock libc++ (simulates the libc++ directory structure).
+// RUN: cp -r %S/Inputs/mock-libcxx %t/
+//
+// Pretend clang is installed beside the mock library that we provided.
+// RUN: echo '[{"directory":"%t","command":"%t/mock-libcxx/bin/clang++ -stdlib=libc++ -target x86_64-apple-darwin -c test.cpp","file":"test.cpp"}]' | sed -e 's/\\/\//g' > %t/compile_commands.json
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-tidy -header-filter='.*' -system-headers -checks='-*,modernize-use-using' "%t/test.cpp" | FileCheck %s
+// CHECK: mock_vector:{{[0-9]+}}:{{[0-9]+}}: warning: use 'using' instead of 'typedef'
+
+#include <mock_vector>
+typedef vector* vec_ptr;