aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Tooling/JSONCompilationDatabase.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-05-31[Tooling] Remove unused includes (NFC) (#142257)Kazu Hirata1-5/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2024-06-03remove goma support from clang (#93942)Takuto Ikuta1-3/+2
goma is deprecated and not maintained anymore. https://chromium.googlesource.com/infra/goma/client/
2023-02-10[NFC][TargetParser] Replace uses of llvm/Support/Host.hArchibald Elliott1-1/+1
The forwarding header is left in place because of its use in `polly/lib/External/isl/interface/extract_interface.cc`, but I have added a GCC warning about the fact it is deprecated, because it is used in `isl` from where it is included by Polly.
2023-02-07[NFC][TargetParser] Remove llvm/ADT/Triple.hArchibald Elliott1-1/+1
I also ran `git clang-format` to get the headers in the right order for the new location, which has changed the order of other headers in two files.
2023-01-14[clang] Remove remaining uses of llvm::Optional (NFC)Kazu Hirata1-1/+0
This patch removes several "using" declarations and #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14[clang] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-1/+1
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14[clang] Add #include <optional> (NFC)Kazu Hirata1-0/+1
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-15[clang][Tooling] Make the filename behaviour consistentKadir Cetinkaya1-3/+2
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
2021-10-13[clang][Tooling] Use Windows command lines on all Windows, except CygwinJeremy Drake1-8/+5
Previously it only used Windows command lines for MSVC triples, but this was causing issues for windows-gnu. In fact, everything 'native' Windows (ie, not Cygwin) should use Windows command line parsing. Reviewed By: mstorsjo Differential Revision: https://reviews.llvm.org/D111195
2021-03-25[NFC] Reordering parameters in getFile and getFileOrSTDINAbhina Sreeskantharajan1-1/+1
In future patches I will be setting the IsText parameter frequently so I will refactor the args to be in the following order. I have removed the FileSize parameter because it is never used. ``` static ErrorOr<std::unique_ptr<MemoryBuffer>> getFile(const Twine &Filename, bool IsText = false, bool RequiresNullTerminator = true, bool IsVolatile = false); static ErrorOr<std::unique_ptr<MemoryBuffer>> getFileOrSTDIN(const Twine &Filename, bool IsText = false, bool RequiresNullTerminator = true); static ErrorOr<std::unique_ptr<MB>> getFileAux(const Twine &Filename, uint64_t MapSize, uint64_t Offset, bool IsText, bool RequiresNullTerminator, bool IsVolatile); static ErrorOr<std::unique_ptr<WritableMemoryBuffer>> getFile(const Twine &Filename, bool IsVolatile = false); ``` Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D99182
2020-12-04[Tooling] JSONCompilationDatabase::loadFromBuffer retains the buffer, copy it.Sam McCall1-1/+1
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-1/+2
commands sccache is a compiler caching tool similar to ccache. Differential Revision: https://reviews.llvm.org/D88790
2020-09-20JSONCompilationDatabase.cpp - cleanup key parsing error checks. NFCI.Simon Pilgrim1-20/+23
Merge the key + sequence/value checks with the key handling code. Reduces the number of key string comparisons and avoids a number of clang static analyzer null dereference warnings.
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-1/+1
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-04Reapply "[llvm][Support] Take in CurrentDirectory as a parameter in ↵Kadir Cetinkaya1-2/+2
ExpandResponseFiles" Attemps to fix windows buildbots.
2019-12-04Revert "[llvm][Support] Take in CurrentDirectory as a parameter in ↵Kadir Cetinkaya1-2/+2
ExpandResponseFiles" This reverts commit 75656005dbc8866e1888932a68a830b0df403560.
2019-12-04[llvm][Support] Take in CurrentDirectory as a parameter in ExpandResponseFilesKadir Cetinkaya1-2/+2
Summary: This is a follow-up to D70769 and D70222, which allows propagation of current directory down to ExpandResponseFiles for handling of relative paths. Previously clients had to mutate FS to achieve that, which is not thread-safe and can even be thread-hostile in the case of real file system. Reviewers: sammccall Subscribers: hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D70857
2019-12-04[clang][Tooling] Add support for .rsp files in compile_commands.jsonKadir Cetinkaya1-1/+3
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-07-12Re-land [JSONCompilationDatabase] Strip distcc/ccache/gomacc wrappers from ↵Sam McCall1-4/+46
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-46/+4
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-4/+46
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] Infer target and mode from argv[0] when using ↵Kadir Cetinkaya1-1/+5
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] Don't mmap the JSONCompilationDatabase, it's not correct for ↵Sam McCall1-1/+4
long-lived processes. Reviewers: ilya-biryukov Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61631 llvm-svn: 360122
2019-03-08[clang][Tooling] Delete dots and dotdots when generating absolute pathsKadir Cetinkaya1-0/+1
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
2018-09-14[Tooling] JSONCompilationDatabasePlugin infers compile commands for missing ↵Sam McCall1-1/+4
files Summary: See the existing InterpolatingCompilationDatabase for details on how this works. We've been using this in clangd for a while, the heuristics seem to work well. Reviewers: bkramer Subscribers: ilya-biryukov, ioeric, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D51729 llvm-svn: 342228
2018-05-09Remove \brief commands from doxygen comments.Adrian Prantl1-1/+1
This is similar to the LLVM change https://reviews.llvm.org/D46290. We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46320 llvm-svn: 331834
2018-03-14[Tooling] Fix some Clang-tidy modernize and Include What You Use warnings; ↵Eugene Zelenko1-40/+46
other minor fixes (NFC). llvm-svn: 327573
2017-05-05[Tooling] Remove redundant check, NFCiKrasimir Georgiev1-6/+2
Summary: The Database check looks redundant. Reviewers: bkramer Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D32909 llvm-svn: 302236
2016-12-01Extend CompilationDatabase by a field for the output filenameJoerg Sonnenberger1-2/+8
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-18Fix json compilation database syntax on non-Windows.Zachary Turner1-4/+2
llvm-svn: 279122
2016-08-18Resubmit "[Tooling] Parse compilation database command lines on Windows."Zachary Turner1-12/+42
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-08-17Revert "[Tooling] Parse compilation database command lines on Windows."Zachary Turner1-18/+0
This reverts commit 27a874790fc79f6391ad3703d7c790f51ac6ae1f. After the introduction of windows command line parsing, some unit tests began failing that expect to test gnu style command line quirks. The fix is mechanical but time consuming, so revert this for now. llvm-svn: 278976
2016-08-17[Tooling] Parse compilation database command lines on Windows.Zachary Turner1-0/+18
When a compilation database is used on Windows, the command lines cannot be parsed using the standard GNU style syntax. LLVM provides functions for parsing Windows style command lines, so use them where appropriate. After this patch, clang-tidy runs correctly on Windows. Reviewed by: alexfh Differential Revision: https://reviews.llvm.org/D23455 llvm-svn: 278964
2015-09-22[tooling] Provide the compile commands of the JSON database in the order ↵Argyrios Kyrtzidis1-7/+4
that they were provided in the JSON file. This is useful for debugging of issues and reduction of test cases. For example, an issue may show up due to the order that some commands were processed. It is convenient to be able to remove commands from the file and still preserve the order that they are returned, instead of getting a completely different order when removing a few commands. llvm-svn: 248292
2015-09-11[tooling] In CompileCommand, Expose the 'file' that was associated with the ↵Argyrios Kyrtzidis1-3/+6
command. llvm-svn: 247468
2015-09-08Fix performance regression when running clang tools.Manuel Klimek1-22/+30
Brings tool start time for a large synthetic test case down from (on my machine) 4 seconds to 0.5 seconds. llvm-svn: 247018
2015-08-14Add structed way to express command line options in the compilation database.Manuel Klimek1-27/+42
Currently, arguments are passed via the string attribute 'command', assuming a shell-escaped / quoted command line to extract the original arguments. This works well enough on Unix systems, but turns out to be problematic for Windows tools to generate. This CL adds a new attribute 'arguments', an array of strings, which specifies the exact command line arguments. If 'arguments' is available in the compilation database, it is preferred to 'commands'. Currently there is no plan to retire 'commands': there are enough different use cases where users want to create their own mechanism for creating compilation databases, that it doesn't make sense to force them all to implement shell command line parsing. Patch by Daniel Dilts. llvm-svn: 245036
2015-05-29Replace push_back(Constructor(foo)) with emplace_back(foo) for non-trivial typesBenjamin Kramer1-4/+4
If the type isn't trivially moveable emplace can skip a potentially expensive move. It also saves a couple of characters. Call sites were found with the ASTMatcher + some semi-automated cleanup. memberCallExpr( argumentCountIs(1), callee(methodDecl(hasName("push_back"))), on(hasType(recordDecl(has(namedDecl(hasName("emplace_back")))))), hasArgument(0, bindTemporaryExpr( hasType(recordDecl(hasNonTrivialDestructor())), has(constructExpr()))), unless(isInTemplateInstantiation())) No functional change intended. llvm-svn: 238601
2015-03-18Remove many superfluous SmallString::str() calls.Yaron Keren1-3/+3
Now that SmallString is a first-class citizen, most SmallString::str() calls are not required. This patch removes a whole bunch of them, yet there are lots more. There are two use cases where str() is really needed: 1) To use one of StringRef member functions which is not available in SmallString. 2) To convert to std::string, as StringRef implicitly converts while SmallString do not. We may wish to change this, but it may introduce ambiguity. llvm-svn: 232622
2014-08-08Sure-up MemoryBuffer ownership in JSONCompilationDatabase's ctor.David Blaikie1-2/+2
llvm-svn: 215246
2014-08-08CompilationDatabase: Sure-up ownership of compilation databases using ↵David Blaikie1-7/+7
std::unique_ptr Diving into the memory leaks fixed by r213851 there was one case of a memory leak of a CompilationDatabase due to not properly taking ownership of the result of "CompilationDatabase::autoDetectFromSource". Given that both implementations and callers have been using unique_ptr to own CompilationDatabase objects - make this explicit in the API to reduce the risk of further leaks. llvm-svn: 215215
2014-07-06Update for llvm api change.Rafael Espindola1-5/+4
llvm-svn: 212408
2014-06-12Include system_error directly.Rafael Espindola1-1/+1
llvm-svn: 210802
2014-06-12Replace llvm::error_code with std::error_code.Rafael Espindola1-2/+2
llvm-svn: 210780
2014-06-01Don't compare an error_code with nullptr.Rafael Espindola1-1/+1
llvm-svn: 209993
2014-05-20[C++11] Use 'nullptr'. Tooling edition.Craig Topper1-14/+14
llvm-svn: 209192
2014-03-15[C++11] Add 'override' keyword to virtual methods that override their base ↵Craig Topper1-2/+2
class. llvm-svn: 203999
2014-03-07Replace OwningPtr with std::unique_ptr.Ahmed Charles1-5/+5
This compiles cleanly with lldb/lld/clang-tools-extra/llvm. llvm-svn: 203279
2014-03-07Change OwningPtr::take() to OwningPtr::release().Ahmed Charles1-5/+5
This is a precursor to moving to std::unique_ptr. llvm-svn: 203275