diff options
author | Haojian Wu <hokein@google.com> | 2017-10-26 08:37:25 +0000 |
---|---|---|
committer | Haojian Wu <hokein@google.com> | 2017-10-26 08:37:25 +0000 |
commit | a94bb25b1400abef481f2a4411e8be005536b892 (patch) | |
tree | 6a8dcec4ed160a96141e70b64c1c1dc56f0c800f | |
parent | 2310743d9c29baefb4ef92be3ef1acac8900ce83 (diff) |
[clang-tidy ObjC] [2/3] Support non-C++ files in ClangTidyTest
Summary:
This is part 2 of 3 of a series of changes to improve
Objective-C linting in clang-tidy.
Currently, `clang::tidy::test::runCheckOnCode()` assumes all files
are C++ and unconditionally adds `-std=c++11` to the list of
`clang-tidy` options.
This updates the logic to check the extension of the source file
and only add `-std=c++11` if the extension indicates C++ or
Objective-C++.
Depends On D39188
Test Plan:
ninja ClangTidyTests && \
./tools/clang/tools/extra/unittests/clang-tidy/ClangTidyTests
Patch by Ben Hamilton!
Reviewers: hokein, alexfh
Reviewed By: hokein
Subscribers: Wizard
Differential Revision: https://reviews.llvm.org/D39189
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@316645 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | unittests/clang-tidy/ClangTidyTest.h | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/unittests/clang-tidy/ClangTidyTest.h b/unittests/clang-tidy/ClangTidyTest.h index 6dfce90f..197c137f 100644 --- a/unittests/clang-tidy/ClangTidyTest.h +++ b/unittests/clang-tidy/ClangTidyTest.h @@ -18,6 +18,7 @@ #include "clang/Tooling/Refactoring.h" #include "clang/Tooling/Tooling.h" #include "llvm/ADT/Optional.h" +#include "llvm/Support/Path.h" #include <map> #include <memory> @@ -83,12 +84,19 @@ runCheckOnCode(StringRef Code, std::vector<ClangTidyError> *Errors = nullptr, ClangTidyGlobalOptions(), Options)); ClangTidyDiagnosticConsumer DiagConsumer(Context); - std::vector<std::string> ArgCXX11(1, "clang-tidy"); - ArgCXX11.push_back("-fsyntax-only"); - ArgCXX11.push_back("-std=c++11"); - ArgCXX11.push_back("-Iinclude"); - ArgCXX11.insert(ArgCXX11.end(), ExtraArgs.begin(), ExtraArgs.end()); - ArgCXX11.push_back(Filename.str()); + std::vector<std::string> Args(1, "clang-tidy"); + Args.push_back("-fsyntax-only"); + std::string extension(llvm::sys::path::extension(Filename.str())); + if (extension == ".m" || extension == ".mm") { + Args.push_back("-fobjc-abi-version=2"); + Args.push_back("-fobjc-arc"); + } + if (extension == ".cc" || extension == ".cpp" || extension == ".mm") { + Args.push_back("-std=c++11"); + } + Args.push_back("-Iinclude"); + Args.insert(Args.end(), ExtraArgs.begin(), ExtraArgs.end()); + Args.push_back(Filename.str()); ast_matchers::MatchFinder Finder; llvm::IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem( @@ -99,7 +107,7 @@ runCheckOnCode(StringRef Code, std::vector<ClangTidyError> *Errors = nullptr, SmallVector<std::unique_ptr<ClangTidyCheck>, 1> Checks; CheckFactory<CheckList...>::createChecks(&Context, Checks); tooling::ToolInvocation Invocation( - ArgCXX11, new TestClangTidyAction(Checks, Finder, Context), Files.get()); + Args, new TestClangTidyAction(Checks, Finder, Context), Files.get()); InMemoryFileSystem->addFile(Filename, 0, llvm::MemoryBuffer::getMemBuffer(Code)); for (const auto &FileContent : PathsToContent) { |