[PATCH] D23409: Make clang-tidy work with clang-cl

Zachary Turner via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 11 10:02:19 PDT 2016


zturner created this revision.
zturner added reviewers: alexfh, djasper, rnk.
zturner added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

Attempting to run clang-tidy with the clang-cl driver results in a number of warnings and errors that make the tool unusable.  The two main issues, and the solutions implemented here are:

  # Command lines are tokenized differently on Windows and non-windows platforms.  Using standard tokenization on Windows leads to -- among other things -- all path separators being stripped from paths.  Obviously this won't work, so the fix implemented here is to use the correct windows command line tokenizer when clang-tidy is running on Windows.
  # The underlying clang driver does not attempt to auto-detect driver mode (CL, GCC, etc) from the program name.  It relies only on the existence of a `--driver-mode=<mode>` option.  We already have a function to detect the driver mode based on the program name, so the solution implemented here is to use the program name as a default, which will be overridden by the existence of a `--driver-mode` option.

With this patch, clang-tidy runs with clang-cl.

```
D:\src\llvm\tools\lldb>d:\src\llvmbuild\ninja\bin\clang-tidy.exe source\lldb.cpp
1448 warnings generated.
warning: argument unused during compilation: '-mincremental-linker-compatible' [clang-diagnostic-unused-command-line-argument]
warning: unknown argument ignored in clang-cl: '-resource-dir=d:\src\llvmbuild\ninja\bin\..\lib\clang\4.0.0' [clang-diagnostic-unk
nown-argument]
D:\src\llvm\tools\lldb\source\lldb.cpp:71:24: warning: invalid case style for variable 'g_version_str' [readability-identifier-nam
ing]
    static std::string g_version_str;
                       ^
D:\src\llvm\tools\lldb\source\lldb.cpp:76:22: warning: invalid case style for variable 'lldb_repo' [readability-identifier-naming]

        const char * lldb_repo = GetLLDBRepository();
                     ^
D:\src\llvm\tools\lldb\source\lldb.cpp:83:21: warning: invalid case style for variable 'lldb_rev' [readability-identifier-naming]
        const char *lldb_rev = GetLLDBRevision();
                    ^
D:\src\llvm\tools\lldb\source\lldb.cpp:89:21: warning: invalid case style for variable 'clang_rev' [readability-identifier-naming]

        std::string clang_rev (clang::getClangRevision());
                    ^
D:\src\llvm\tools\lldb\source\lldb.cpp:95:21: warning: invalid case style for variable 'llvm_rev' [readability-identifier-naming]
        std::string llvm_rev (clang::getLLVMRevision());
                    ^
Suppressed 1441 warnings (1441 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as
well.
```

https://reviews.llvm.org/D23409

Files:
  include/clang/Driver/Driver.h
  lib/Driver/Driver.cpp
  lib/Tooling/JSONCompilationDatabase.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23409.67698.patch
Type: text/x-patch
Size: 4541 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160811/d75357e3/attachment.bin>


More information about the cfe-commits mailing list