<div dir="ltr">Thanks! I didn't see this warning when running check-clang-tools on my machine. Fixed in r330327.</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 19, 2018 at 7:39 AM, Mikael Holmén <span dir="ltr"><<a href="mailto:mikael.holmen@ericsson.com" target="_blank">mikael.holmen@ericsson.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<div><div class="h5"><br>
<br>
On 04/18/2018 10:54 AM, Haojian Wu via cfe-commits wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: hokein<br>
Date: Wed Apr 18 01:54:28 2018<br>
New Revision: 330245<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=330245&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject?rev=330245&view=rev</a><br>
Log:<br>
[clang-tidy] Fix clang-tidy doesn't read .clangtidy configuration file.<br>
<br>
Summary: Fix <a href="https://bugs.llvm.org/show_bug.cgi?id=34900" rel="noreferrer" target="_blank">https://bugs.llvm.org/show_bug<wbr>.cgi?id=34900</a>.<br>
<br>
Reviewers: alexfh<br>
<br>
Reviewed By: alexfh<br>
<br>
Subscribers: JonasToth, klimek, xazax.hun, cfe-commits<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D45697" rel="noreferrer" target="_blank">https://reviews.llvm.org/D4569<wbr>7</a><br>
<br>
Added:<br>
clang-tools-extra/trunk/test/<wbr>clang-tidy/read_file_config.cp<wbr>p<br>
Modified:<br>
clang-tools-extra/trunk/<wbr>clang-tidy/ClangTidyOptions.<wbr>cpp<br>
clang-tools-extra/trunk/<wbr>clang-tidy/ClangTidyOptions.h<br>
clang-tools-extra/trunk/<wbr>clang-tidy/tool/ClangTidyMain.<wbr>cpp<br>
<br>
Modified: clang-tools-extra/trunk/clang-<wbr>tidy/ClangTidyOptions.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.cpp?rev=330245&r1=330244&r2=330245&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clang-tidy/ClangTidyOptions.<wbr>cpp?rev=330245&r1=330244&r2=<wbr>330245&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clang-<wbr>tidy/ClangTidyOptions.cpp (original)<br>
+++ clang-tools-extra/trunk/clang-<wbr>tidy/ClangTidyOptions.cpp Wed Apr 18 01:54:28 2018<br>
@@ -204,9 +204,12 @@ ConfigOptionsProvider::getRawO<wbr>ptions(llv<br>
FileOptionsProvider::FileOptio<wbr>nsProvider(<br>
const ClangTidyGlobalOptions &GlobalOptions,<br>
const ClangTidyOptions &DefaultOptions,<br>
- const ClangTidyOptions &OverrideOptions)<br>
+ const ClangTidyOptions &OverrideOptions,<br>
+ llvm::IntrusiveRefCntPtr<vfs::<wbr>FileSystem> VFS)<br>
: DefaultOptionsProvider(GlobalO<wbr>ptions, DefaultOptions),<br>
- OverrideOptions(OverrideOption<wbr>s) {<br>
+ OverrideOptions(OverrideOption<wbr>s), FS(std::move(VFS)) {<br>
+ if (!FS)<br>
+ FS = vfs::getRealFileSystem();<br>
ConfigHandlers.emplace_back(".<wbr>clang-tidy", parseConfiguration);<br>
}<br>
@@ -224,14 +227,19 @@ FileOptionsProvider::FileOptio<wbr>nsProvider<br>
std::vector<OptionsSource><br>
FileOptionsProvider::getRawOpt<wbr>ions(StringRef FileName) {<br>
DEBUG(llvm::dbgs() << "Getting options for file " << FileName << "...\n");<br>
+ assert(FS && "FS must be set.");<br>
+<br>
+ llvm::SmallString<128> AbsoluteFilePath(FileName);<br>
+ if (std::error_code ec = FS->makeAbsolute(AbsoluteFileP<wbr>ath))<br>
+ return {};<br>
<br>
</blockquote>
<br></div></div>
This causes a compilation warning:<br>
<br>
../tools/clang/tools/extra/cla<wbr>ng-tidy/ClangTidyOptions.cpp:<wbr>233:23: error: unused variable 'ec' [-Werror,-Wunused-variable]<span class=""><br>
if (std::error_code ec = FS->makeAbsolute(AbsoluteFileP<wbr>ath))<br></span>
^<br>
1 error generated.<br>
<br>
Regards,<br>
Mikael<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
std::vector<OptionsSource> RawOptions =<br>
- DefaultOptionsProvider::getRaw<wbr>Options(FileName);<br>
+ DefaultOptionsProvider::getRaw<wbr>Options(AbsoluteFilePath.str()<wbr>);<br>
OptionsSource CommandLineOptions(OverrideOpt<wbr>ions,<br>
<wbr>OptionsSourceTypeCheckCommandL<wbr>ineOption);<br>
// Look for a suitable configuration file in all parent directories of the<br>
// file. Start with the immediate parent directory and move up.<br>
- StringRef Path = llvm::sys::path::parent_path(F<wbr>ileName);<br>
+ StringRef Path = llvm::sys::path::parent_path(A<wbr>bsoluteFilePath.str());<br>
for (StringRef CurrentPath = Path; !CurrentPath.empty();<br>
CurrentPath = llvm::sys::path::parent_path(C<wbr>urrentPath)) {<br>
llvm::Optional<OptionsSource> Result;<br>
<br>
Modified: clang-tools-extra/trunk/clang-<wbr>tidy/ClangTidyOptions.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.h?rev=330245&r1=330244&r2=330245&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clang-tidy/ClangTidyOptions.h?<wbr>rev=330245&r1=330244&r2=<wbr>330245&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clang-<wbr>tidy/ClangTidyOptions.h (original)<br>
+++ clang-tools-extra/trunk/clang-<wbr>tidy/ClangTidyOptions.h Wed Apr 18 01:54:28 2018<br>
@@ -13,7 +13,9 @@<br>
#include "llvm/ADT/Optional.h"<br>
#include "llvm/ADT/StringMap.h"<br>
#include "llvm/ADT/StringRef.h"<br>
+#include "llvm/ADT/IntrusiveRefCntPtr.h<wbr>"<br>
#include "llvm/Support/ErrorOr.h"<br>
+#include "clang/Basic/VirtualFileSystem<wbr>.h"<br>
#include <functional><br>
#include <map><br>
#include <string><br>
@@ -221,7 +223,8 @@ public:<br>
/// whatever options are read from the configuration file.<br>
FileOptionsProvider(const ClangTidyGlobalOptions &GlobalOptions,<br>
const ClangTidyOptions &DefaultOptions,<br>
- const ClangTidyOptions &OverrideOptions);<br>
+ const ClangTidyOptions &OverrideOptions,<br>
+ llvm::IntrusiveRefCntPtr<vfs::<wbr>FileSystem> FS = nullptr);<br>
/// \brief Initializes the \c FileOptionsProvider instance with a custom set<br>
/// of configuration file handlers.<br>
@@ -255,6 +258,7 @@ protected:<br>
llvm::StringMap<OptionsSource> CachedOptions;<br>
ClangTidyOptions OverrideOptions;<br>
ConfigFileHandlers ConfigHandlers;<br>
+ llvm::IntrusiveRefCntPtr<vfs::<wbr>FileSystem> FS;<br>
};<br>
/// \brief Parses LineFilter from JSON and stores it to the \p Options.<br>
<br>
Modified: clang-tools-extra/trunk/clang-<wbr>tidy/tool/ClangTidyMain.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp?rev=330245&r1=330244&r2=330245&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>clang-tidy/tool/ClangTidyMain.<wbr>cpp?rev=330245&r1=330244&r2=<wbr>330245&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clang-<wbr>tidy/tool/ClangTidyMain.cpp (original)<br>
+++ clang-tools-extra/trunk/clang-<wbr>tidy/tool/ClangTidyMain.cpp Wed Apr 18 01:54:28 2018<br>
@@ -286,7 +286,8 @@ static void printProfileData(const Profi<br>
OS.flush();<br>
}<br>
-static std::unique_ptr<ClangTidyOptio<wbr>nsProvider> createOptionsProvider() {<br>
+static std::unique_ptr<ClangTidyOptio<wbr>nsProvider> createOptionsProvider(<br>
+ llvm::IntrusiveRefCntPtr<vfs:<wbr>:FileSystem> FS) {<br>
ClangTidyGlobalOptions GlobalOptions;<br>
if (std::error_code Err = parseLineFilter(LineFilter, GlobalOptions)) {<br>
llvm::errs() << "Invalid LineFilter: " << Err.message() << "\n\nUsage:\n";<br>
@@ -334,7 +335,7 @@ static std::unique_ptr<ClangTidyOptio<wbr>nsP<br>
}<br>
}<br>
return llvm::make_unique<FileOptionsP<wbr>rovider>(GlobalOptions, DefaultOptions,<br>
- OverrideOptions);<br>
+ OverrideOptions, std::move(FS));<br>
}<br>
llvm::IntrusiveRefCntPtr<vfs::<wbr>FileSystem><br>
@@ -364,8 +365,13 @@ getVfsOverlayFromFile(const std::string<br>
static int clangTidyMain(int argc, const char **argv) {<br>
CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory,<br>
cl::ZeroOrMore);<br>
+ llvm::IntrusiveRefCntPtr<vfs::<wbr>FileSystem> BaseFS(<br>
+ VfsOverlay.empty() ? vfs::getRealFileSystem()<br>
+ : getVfsOverlayFromFile(VfsOverl<wbr>ay));<br>
+ if (!BaseFS)<br>
+ return 1;<br>
- auto OwningOptionsProvider = createOptionsProvider();<br>
+ auto OwningOptionsProvider = createOptionsProvider(BaseFS);<br>
auto *OptionsProvider = OwningOptionsProvider.get();<br>
if (!OptionsProvider)<br>
return 1;<br>
@@ -432,12 +438,6 @@ static int clangTidyMain(int argc, const<br>
llvm::cl::PrintHelpMessage(/*H<wbr>idden=*/false, /*Categorized=*/true);<br>
return 1;<br>
}<br>
- llvm::IntrusiveRefCntPtr<vfs::<wbr>FileSystem> BaseFS(<br>
- VfsOverlay.empty() ? vfs::getRealFileSystem()<br>
- : getVfsOverlayFromFile(VfsOverl<wbr>ay));<br>
- if (!BaseFS)<br>
- return 1;<br>
-<br>
ProfileData Profile;<br>
llvm::InitializeAllTargetInfos<wbr>();<br>
<br>
Added: clang-tools-extra/trunk/test/c<wbr>lang-tidy/read_file_config.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/read_file_config.cpp?rev=330245&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/clang-tools-extra/trunk/<wbr>test/clang-tidy/read_file_<wbr>config.cpp?rev=330245&view=<wbr>auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/test/c<wbr>lang-tidy/read_file_config.cpp (added)<br>
+++ clang-tools-extra/trunk/test/c<wbr>lang-tidy/read_file_config.cpp Wed Apr 18 01:54:28 2018<br>
@@ -0,0 +1,12 @@<br>
+// RUN: mkdir -p %T/read-file-config/<br>
+// RUN: cp %s %T/read-file-config/test.cpp<br>
+// RUN: echo 'Checks: "-*,modernize-use-nullptr"' > %T/read-file-config/.clang-tid<wbr>y<br>
+// RUN: echo '[{"command": "cc -c -o test.o test.cpp", "directory": "%T/read-file-config", "file": "%T/read-file-config/test.cpp"<wbr>}]' > %T/read-file-config/compile_co<wbr>mmands.json<br>
+// RUN: clang-tidy %T/read-file-config/test.cpp | not grep "warning: .*\[clang-analyzer-deadcode.De<wbr>adStores\]$"<br>
+// RUN: clang-tidy -checks="-*,clang-analyzer-*" %T/read-file-config/test.cpp | grep "warning: .*\[clang-analyzer-deadcode.De<wbr>adStores\]$"<br>
+<br>
+void f() {<br>
+ int x;<br>
+ x = 1;<br>
+ x = 2;<br>
+}<br>
<br>
<br>
______________________________<wbr>_________________<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/<wbr>mailman/listinfo/cfe-commits</a><br>
<br>
</blockquote>
</div></div></blockquote></div><br></div>