[all-commits] [llvm/llvm-project] e030ce: [Tooling] Handle compilation databases containing ...

Alexandre Ganea via All-commits all-commits at lists.llvm.org
Wed Mar 24 13:02:12 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e030ce3ec790a0017ec789b4f487afec99e1cac9
      https://github.com/llvm/llvm-project/commit/e030ce3ec790a0017ec789b4f487afec99e1cac9
  Author: Janusz Nykiel <janusz.nykiel at ubisoft.com>
  Date:   2021-03-24 (Wed, 24 Mar 2021)

  Changed paths:
    M clang/lib/Tooling/ArgumentsAdjusters.cpp
    M clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
    M clang/lib/Tooling/Tooling.cpp
    M clang/unittests/Tooling/CompilationDatabaseTest.cpp

  Log Message:
  -----------
  [Tooling] Handle compilation databases containing commands with double dashes

As of CMake commit https://gitlab.kitware.com/cmake/cmake/-/commit/d993ebd4,
which first appeared in CMake 3.19.x series, in the compile commands for
clang-cl, CMake puts `--` before the input file. When operating on such a
database, the `InterpolatingCompilationDatabase` - specifically, the
`TransferableCommand` constructor - does not recognize that pattern and so, does
not strip the input, or the double dash when 'transferring' the compile command.
This results in a incorrect compile command - with the double dash and old input
file left in, and the language options and new input file appended after them,
where they're all treated as inputs, including the language version option.

Test files for some tests have names similar enough to be matched to commands
from the database, e.g.:

`.../path-mappings.test.tmp/server/bar.cpp`

can be matched to:

`.../Driver/ToolChains/BareMetal.cpp`

etc. When that happens, the tool being tested tries to use the matched, and
incorrectly 'transferred' compile command, and fails, reporting errors similar
to:

`error: no such file or directory: '/std:c++14'; did you mean '/std:c++14'? [clang-diagnostic-error]`

This happens in at least 4 tests:

  Clang Tools :: clang-tidy/checkers/performance-trivially-destructible.cpp
  Clangd :: check-fail.test
  Clangd :: check.test
  Clangd :: path-mappings.test

The fix for `TransferableCommand` removes the `--` and everything after it when
determining the arguments that apply to the new file. `--` is inserted in the
'transferred' command if the new file name starts with `-` and when operating in
clang-cl mode, also `/`. Additionally, other places in the code known to do
argument adjustment without accounting for the `--` and causing the tests to
fail are fixed as well.

Differential Revision: https://reviews.llvm.org/D98824




More information about the All-commits mailing list