[clang-tools-extra] r348365 - Move detection of libc++ include dirs to Driver on MacOS

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 5 06:24:14 PST 2018


Author: ibiryukov
Date: Wed Dec  5 06:24:14 2018
New Revision: 348365

URL: http://llvm.org/viewvc/llvm-project?rev=348365&view=rev
Log:
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

Added:
    clang-tools-extra/trunk/test/clang-tidy/Inputs/mock-libcxx/include/c++/v1/mock_vector
    clang-tools-extra/trunk/test/clang-tidy/clang-tidy-mac-libcxx.cpp

Added: clang-tools-extra/trunk/test/clang-tidy/Inputs/mock-libcxx/include/c++/v1/mock_vector
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/Inputs/mock-libcxx/include/c%2B%2B/v1/mock_vector?rev=348365&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/Inputs/mock-libcxx/include/c++/v1/mock_vector (added)
+++ clang-tools-extra/trunk/test/clang-tidy/Inputs/mock-libcxx/include/c++/v1/mock_vector Wed Dec  5 06:24:14 2018
@@ -0,0 +1,2 @@
+class vector {};
+typedef vector* vector_ptr;

Added: clang-tools-extra/trunk/test/clang-tidy/clang-tidy-mac-libcxx.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/clang-tidy-mac-libcxx.cpp?rev=348365&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/clang-tidy-mac-libcxx.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/clang-tidy-mac-libcxx.cpp Wed Dec  5 06:24:14 2018
@@ -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;




More information about the cfe-commits mailing list