aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Tooling/CompilationDatabaseTest.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-07-31NFC: Clean up construction of IntrusiveRefCntPtr from raw pointers for ↵James Y Knight1-1/+2
llvm::vfs::FileSystem. (#151407) This switches to `makeIntrusiveRefCnt<FileSystem>` where creating a new object, and to passing/returning by `IntrusiveRefCntPtr<FileSystem>` instead of `FileSystem*` or `FileSystem&`, when dealing with existing objects. Part of cleanup #151026.
2025-05-04[clang] Remove unused local variables (NFC) (#138468)Kazu Hirata1-1/+0
2024-06-03remove goma support from clang (#93942)Takuto Ikuta1-1/+0
goma is deprecated and not maintained anymore. https://chromium.googlesource.com/infra/goma/client/
2024-01-19[Tooling] Fix FixedCompilationDatabase with header compile flags (#73913)Sam McCall1-1/+19
Summary: The logic to strip positional args feels very fragile, but it's terribly useful when you want to use a tool on a file and have the exact argv. Today doesn't work with header-parsing actions because these are "precompile" rather than "compile", from tooling's perspective it's all the same. Reviewers: kadircet Subscribers:
2023-08-14Improve reliability of CompilationDatabaseTestEllis Hoag1-9/+8
We've seen `CompilationDatabaseTest.cpp` fail because the order of the files returned by `getAllFiles()` was in a different order than expected. Use `UnorderedElementsAreArray()` to handle different file orders. Reviewed By: kadircet Differential Revision: https://reviews.llvm.org/D157904
2022-11-26[clang] Use std::size (NFC)Kazu Hirata1-2/+2
std::size, introduced in C++17, allows us to directly obtain the number of elements of an array.
2022-11-15[clang][Tooling] Sort filenames in testKadir Cetinkaya1-3/+6
2022-11-15[clang][Tooling] Make the filename behaviour consistentKadir Cetinkaya1-9/+25
Dotdots were removed only when converting a relative path to absolute one. This patch makes the behaviour consistent for absolute file paths by removing them in that case as well. Also updates the documentation to mention the behaviour. Fixes https://github.com/clangd/clangd/issues/1317 Differential Revision: https://reviews.llvm.org/D137962
2022-09-08[clang] Use std::size instead of llvm::array_lengthofJoe Loser1-1/+1
LLVM contains a helpful function for getting the size of a C-style array: `llvm::array_lengthof`. This is useful prior to C++17, but not as helpful for C++17 or later: `std::size` already has support for C-style arrays. Change call sites to use `std::size` instead. Leave the few call sites that use a locally defined `array_lengthof` that are meant to test previous bugs with NTTPs in clang analyzer and SemaTemplate. Differential Revision: https://reviews.llvm.org/D133520
2022-04-25compile commands header to source heuristic lower-cases filenames before ↵Ishaan Gandhi1-0/+8
inferring file types This leads to ".C" files being rewritten as ".c" files and being inferred to be "c" files as opposed to "c++" files. Fixes https://github.com/clangd/clangd/issues/1108 Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D124262
2022-01-26Revert "Rename llvm::array_lengthof into llvm::size to match std::size from ↵Benjamin Kramer1-1/+1
C++17" This reverts commit ef8206320769ad31422a803a0d6de6077fd231d2. - It conflicts with the existing llvm::size in STLExtras, which will now never be called. - Calling it without llvm:: breaks C++17 compat
2022-01-26Rename llvm::array_lengthof into llvm::size to match std::size from C++17serge-sans-paille1-1/+1
As a conquence move llvm::array_lengthof from STLExtras.h to STLForwardCompat.h (which is included by STLExtras.h so no build breakage expected).
2022-01-11[Tooling] When transferring compile commands between files, always use '--'Sam McCall1-13/+4
"driver <flags> -- <input>" is a particularly convenient form of the compile command to manipulate, with fewer special cases to handle. Guaranteeing that the output command is of that form is cheap and makes it easier to consume the result in some cases. Differential Revision: https://reviews.llvm.org/D116721
2021-06-30[clang] Fix UB when string.front() is used for the empty stringDmitry Polukhin1-0/+11
Compilation database might have empty string as a command line argument. But ExpandResponseFilesDatabase::expand doesn't expect this and assumes that string.front() can be used for any argument. It is undefined behaviour if string is empty. With debug build mode it causes crash in clangd. Test Plan: check-clang Differential Revision: https://reviews.llvm.org/D105120
2021-06-25[clang] Rename StringRef _lower() method calls to _insensitive()Martin Storsjö1-1/+1
This is mostly a mechanical change, but a testcase that contains parts of the StringRef class (clang/test/Analysis/llvm-conventions.cpp) isn't touched.
2021-03-24[Tooling] Handle compilation databases containing commands with double dashesJanusz Nykiel1-6/+30
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
2021-03-01[clangd] Use flags from open files when opening headers they includeSam McCall1-0/+12
Currently our strategy for getting header compile flags is something like: A) look for flags for the header in compile_commands.json This basically never works, build systems don't generate this info. B) try to match to an impl file in compile_commands.json and use its flags This only (mostly) works if the headers are in the same project. C) give up and use fallback flags This kind of works for stdlib in the default configuration, and otherwise doesn't. Obviously there are big gaps here. This patch inserts a new attempt between A and B: if the header is transitively included by any open file (whether same project or not), then we use its compile command. This doesn't make any attempt to solve some related problems: - parsing non-self-contained header files in context (importing PP state) - using the compile flags of non-opened candidate files found in the index Fixes https://github.com/clangd/clangd/issues/123 Fixes https://github.com/clangd/clangd/issues/695 See https://github.com/clangd/clangd/issues/519 Differential Revision: https://reviews.llvm.org/D97351
2020-12-07Add ability to load a FixedCompilationDatabase from a buffer.Sam McCall1-0/+21
Previously, loading one from a file meant allowing the library to do the IO. Clangd would prefer to do such IO itself (e.g. to allow caching). Differential Revision: https://reviews.llvm.org/D92640
2020-12-04[Tooling] JSONCompilationDatabase::loadFromBuffer retains the buffer, copy it.Sam McCall1-1/+3
This function doesn't seem to be used in-tree outside tests. However clangd wants to use it soon, and having the CDB be self-contained seems reasonable. Differential Revision: https://reviews.llvm.org/D92646
2020-10-27[libTooling] Recognize sccache as a compiler wrapper in compilation database ↵Nathan Ridge1-0/+1
commands sccache is a compiler caching tool similar to ccache. Differential Revision: https://reviews.llvm.org/D88790
2020-07-17[clang][Tooling] Try to avoid file system access if there is no record for ↵Aleksandr Platonov1-0/+9
the file in compile_commads.json Summary: If there is no record in compile_commands.json, we try to find suitable record with `MatchTrie.findEquivalent()` call. This is very expensive operation with a lot of `llvm::sys::fs::equivalent()` calls in some cases. This patch disables file symlinks for performance reasons. Example scenario without this patch: - compile_commands.json generated at clangd build (contains ~3000 files). - it tooks more than 1 second to get compile command for newly created file in the root folder of LLVM project. - we wait for 1 second every time when clangd requests compile command for this file (at file change). Reviewers: sammccall, kadircet, hokein Reviewed By: sammccall Subscribers: chandlerc, djasper, klimek, ilya-biryukov, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D83621
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-6/+6
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2019-12-20[clang][Tooling] Prefer -x over -std when interpolatingKadir Cetinkaya1-0/+4
Summary: Currently interpolation logic prefers -std over -x. But the latter is a more strong signal, so this patch inverts the order and only makes use of -std if -x didn't exist. Fixes https://github.com/clangd/clangd/issues/185 Thanks @sammccall for tracking this down! Reviewers: sammccall Subscribers: ilya-biryukov, usaxena95, cfe-commits, sammccall Tags: #clang Differential Revision: https://reviews.llvm.org/D71727
2019-12-04[clang][Tooling] Add support for .rsp files in compile_commands.jsonKadir Cetinkaya1-0/+30
Summary: Add support for .rsp files. Fixes https://github.com/clangd/clangd/issues/81 Patch By: liu hui(@lh123) Reviewers: sammccall, ilya-biryukov, hokein, kadircet Reviewed By: kadircet Subscribers: merge_guards_bot, mgorny, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D70222
2019-08-26Remove unused variables.Benjamin Kramer1-2/+0
llvm-svn: 369965
2019-08-14[Clang] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere1-3/+3
Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. Differential revision: https://reviews.llvm.org/D66259 llvm-svn: 368942
2019-07-12Re-land [JSONCompilationDatabase] Strip distcc/ccache/gomacc wrappers from ↵Sam McCall1-0/+27
parsed commands. Use //net/dir like other test cases for windows compatibility llvm-svn: 365975
2019-07-12Revert "[JSONCompilationDatabase] Strip distcc/ccache/gomacc wrappers from ↵Russell Gallop1-24/+0
parsed commands." New test is failing on Windows bot This reverts commit 9c0391b36a76f8e3949588de3f44b7314c2318bf. llvm-svn: 365906
2019-07-12[JSONCompilationDatabase] Strip distcc/ccache/gomacc wrappers from parsed ↵Sam McCall1-0/+24
commands. Summary: It's common to use compiler wrappers by setting CC="gomacc clang++". This results in both args appearing in compile_commands.json, and clang's driver can't handle this. This patch attempts to recognize this pattern (by looking for well-known wrappers) and dropping argv0 in this case. It conservatively ignores other cases for now: - wrappers with unknown names - wrappers that accept -flags - wrappers where the compiler to use is implied (usually cc or gcc) This is done at the JSONCompilationDatabase level rather than somewhere more fundamental, as (hopefully) this isn't a general conceptual problem, but a messy aspect of the nature of the ecosystem around compile_commands.json. i.e. compilation databases more tightly tied to the build system should not have this problem. Reviewers: phosek, klimek Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64297 llvm-svn: 365887
2019-06-26[clang][Tooling] Fix windows build-bots after rL364386Kadir Cetinkaya1-2/+2
llvm-svn: 364396
2019-06-26[clang][Tooling] Infer target and mode from argv[0] when using ↵Kadir Cetinkaya1-3/+33
JSONCompilationDatabase Summary: Wraps JSON compilation database with a target and mode adding database wrapper. So that driver can correctly figure out which toolchain to use. Note that clients that wants to make use of this target discovery mechanism needs to link in TargetsInfos and initialize them at startup. Reviewers: ilya-biryukov Subscribers: mgorny, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63755 llvm-svn: 364386
2019-05-07[Tooling] Add -x flags when inferring compile commands for files with ↵Sam McCall1-2/+5
no/invalid extension. Summary: We treat them as headers, as the motivating case is C++ standard library. Reviewers: kadircet Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61633 llvm-svn: 360153
2019-04-05[Tooling] add a Heuristic field indicating that a CompileCommand was guessed.Sam McCall1-9/+28
Summary: Use cases: - a tool that dumps the heuristic used for each header in a project can be used to evaluate changes to the heuristic - we want to expose this information to users in clangd as it affects accuracy/reliability of editor features - express interpolation tests more directly Reviewers: ilya-biryukov, klimek Subscribers: ioeric, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60194 llvm-svn: 357770
2019-03-08[clang][Tooling] Delete dots and dotdots when generating absolute pathsKadir Cetinkaya1-0/+5
Summary: GetAllFiles interface returns absolute paths, but keeps dots and dot dots. This patch makes those paths canonical by deleting them. Reviewers: hokein Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59079 llvm-svn: 355678
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2019-01-16Reapply [Tooling] Make clang-tool find libc++ dir on mac when running on a ↵Sam McCall1-34/+18
file without compilation database. This reverts commit r351282, and re-lands r351222 and r351229 with the use-after-free fixed. llvm-svn: 351316
2019-01-16Revert "[Tooling] Make clang-tool find libc++ dir on mac when running on a ↵Vlad Tsyrklevich1-18/+34
file without compilation database." This reverts commits r351222 and r351229, they were causing ASan/MSan failures on the sanitizer bots. llvm-svn: 351282
2019-01-15[Tooling] Fix broken compliation databse tests.Haojian Wu1-34/+18
I forgot to update the unittest in r351222. llvm-svn: 351229
2018-09-09[Tooling] Improve handling of CL-style optionsHamza Sood1-3/+30
This patch fixes the handling of clang-cl options in InterpolatingCompilationDatabase. They were previously ignored completely, which led to a lot of bugs: Additional options were being added with the wrong syntax. E.g. a file was specified as C++ by adding -x c++, which causes an error in CL mode. The args were parsed and then rendered, which means that the aliasing information was lost. E.g. /W4 was rendered to -Wall, which in CL mode means -Weverything. CL options were ignored when checking things like -std=, so a lot of logic was being bypassed. Differential Revision: https://reviews.llvm.org/D51321 llvm-svn: 341760
2018-08-28Parse compile commands lazily in InterpolatingCompilationDatabaseIlya Biryukov1-3/+6
Summary: This greatly reduces the time to read 'compile_commands.json'. For Chromium on my machine it's now 0.7 seconds vs 30 seconds before the change. Reviewers: sammccall, jfb Reviewed By: sammccall Subscribers: mgrang, jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D51314 llvm-svn: 340838
2018-07-17[Tooling] Add operator== to CompileCommandSimon Marchi1-0/+28
Summary: It does the obvious thing of comparing all fields. This will be needed for a clangd patch I have in the pipeline. Subscribers: dblaikie, ilya-biryukov, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D49265 llvm-svn: 337284
2018-04-11[Tooling] Correct the "-std" compile command option.Haojian Wu1-2/+2
Summary: "-std c++11" is not valid in compiler, we have to use "-std=c++11". Test in vscode with this patch, code completion for header works as expected. Reviewers: sammccall Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D45512 llvm-svn: 329786
2018-04-09[Tooling] A CompilationDatabase wrapper that infers header commands.Sam McCall1-0/+110
Summary: The wrapper finds the closest matching compile command using filename heuristics and makes minimal tweaks so it can be used with the header. Subscribers: klimek, mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D45006 llvm-svn: 329580
2017-06-29[Tooling] FixedCompilationDatabase should be able to strip positionalAlex Lorenz1-0/+21
arguments when `-fsyntax-only` is used Previously, Clang failed to create a fixed compilation database when the compilation arguments use -fsyntax-only instead of -c. This commit fixes the issue by forcing Clang to look at the compilation job when stripping the positional arguments. Differential Revision: https://reviews.llvm.org/D34687 llvm-svn: 306659
2017-05-24Method loadFromCommandLine should be able to report errorsSerge Pavlov1-10/+22
Now FixedCompilationDatabase::loadFromCommandLine has no means to report which error occurred if it fails to create compilation object. This is a block for implementing D33013, because after that change driver will refuse to create compilation if command line contains erroneous options. This change adds additional argument to loadFromCommandLine, which is assigned error message text if compilation object was not created. This is the same way as other methods of CompilationDatabase report failure. Differential Revision: https://reviews.llvm.org/D33272 llvm-svn: 303741
2017-04-26Revert r301487: Replace HashString algorithm with xxHash64Rui Ueyama1-2/+2
This reverts commit r301487 to make buildbots green. llvm-svn: 301491
2017-04-26Replace HashString algorithm with xxHash64Rui Ueyama1-2/+2
The previous algorithm processed one character at a time, which is very painful on a modern CPU. Replace it with xxHash64, which both already exists in the codebase and is fairly fast. Patch from Scott Smith! Differential Revision: https://reviews.llvm.org/D32509 llvm-svn: 301487
2016-12-01Extend CompilationDatabase by a field for the output filenameJoerg Sonnenberger1-1/+7
In bigger projects like an Operating System, the same source code is often compiled in slightly different ways. This could be the difference between PIC and non-PIC code for static vs dynamic libraries, it could also be the difference between size optimised versions of tools for ramdisk images. At the moment, the compilation database has no way to distinguish such cases. As first step, add a field in the JSON format for it and process it accordingly. Differential Revision: https://reviews.llvm.org/D27138 llvm-svn: 288436
2016-08-18Resubmit "[Tooling] Parse compilation database command lines on Windows."Zachary Turner1-32/+50
This patch introduced the ability to decide at runtime whether to parse JSON compilation database command lines using Gnu syntax or Windows syntax. However, there were many existing unit tests written that hardcoded Gnu-specific paths. These tests were now failing because the auto-detection logic was choosing to parse them using Windows rules. This resubmission of the patch fixes this by introducing an enum which defines the syntax mode, which defaults to auto-detect, but for which the unit tests force Gnu style parsing. Reviewed By: alexfh Differential Revision: https://reviews.llvm.org/D23628 llvm-svn: 279120
2016-07-18[NFC] Header cleanupMehdi Amini1-1/+0
Summary: Removed unused headers, replaced some headers with forward class declarations Patch by: Eugene <claprix@yandex.ru> Differential Revision: https://reviews.llvm.org/D20100 llvm-svn: 275882