summaryrefslogtreecommitdiff
path: root/clang-tools-extra/test
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
commit956af1b25609f7a0eafc524796a3e82321788b9b (patch)
tree6b6c07f760545361ac3db2ba5637a230751586b2 /clang-tools-extra/test
parentc24ae6e42e24adf622c4ad3edeaeaa0f212b79e3 (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
Diffstat (limited to 'clang-tools-extra/test')
-rw-r--r--clang-tools-extra/test/clang-tidy/Inputs/mock-libcxx/include/c++/v1/mock_vector2
-rw-r--r--clang-tools-extra/test/clang-tidy/clang-tidy-mac-libcxx.cpp17
2 files changed, 19 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/Inputs/mock-libcxx/include/c++/v1/mock_vector b/clang-tools-extra/test/clang-tidy/Inputs/mock-libcxx/include/c++/v1/mock_vector
new file mode 100644
index 00000000000..35395267226
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/Inputs/mock-libcxx/include/c++/v1/mock_vector
@@ -0,0 +1,2 @@
+class vector {};
+typedef vector* vector_ptr;
diff --git a/clang-tools-extra/test/clang-tidy/clang-tidy-mac-libcxx.cpp b/clang-tools-extra/test/clang-tidy/clang-tidy-mac-libcxx.cpp
new file mode 100644
index 00000000000..153a5d6e91f
--- /dev/null
+++ b/clang-tools-extra/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;