aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Tooling/ToolingTest.cpp
AgeCommit message (Collapse)AuthorFilesLines
23 hoursNFC: Clean up of IntrusiveRefCntPtr construction from raw pointers. (#151782)James Y Knight1-14/+14
This commit handles the following types: - clang::ExternalASTSource - clang::TargetInfo - clang::ASTContext - clang::SourceManager - clang::FileManager Part of cleanup #151026
2 daysNFC: Clean up construction of IntrusiveRefCntPtr from raw pointers for ↵James Y Knight1-35/+43
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-06-07Revert "[Clang] Add resource_dir_EQ flag to CC1Option group (#140870)" (#142509)Wenju He1-19/+0
This reverts commit c7b8d6e1dcb0a277f95496cbc6bb27143afb80a6. Fix check-clang CodeGenTest.TestNonAlterTest regression, see https://github.com/llvm/llvm-project/pull/140870#issuecomment-2931610238
2025-05-30[Clang] Add resource_dir_EQ flag to CC1Option group (#140870)Wenju He1-0/+19
This PR fixes ClangTool error in -cc1 mode in function injectResourceDir: error: unknown argument: '-resource-dir=
2025-05-22Reapply "[clang] Remove intrusive reference count from `DiagnosticOptions` ↵Jan Svoboda1-4/+4
(#139584)" This reverts commit e2a885537f11f8d9ced1c80c2c90069ab5adeb1d. Build failures were fixed right away and reverting the original commit without the fixes breaks the build again.
2025-05-22Revert "[clang] Remove intrusive reference count from `DiagnosticOptions` ↵Kazu Hirata1-4/+4
(#139584)" This reverts commit 9e306ad4600c4d3392c194a8be88919ee758425c. Multiple builtbot failures have been reported: https://github.com/llvm/llvm-project/pull/139584
2025-05-22[clang] Remove intrusive reference count from `DiagnosticOptions` (#139584)Jan Svoboda1-4/+4
The `DiagnosticOptions` class is currently intrusively reference-counted, which makes reasoning about its lifetime very difficult in some cases. For example, `CompilerInvocation` owns the `DiagnosticOptions` instance (wrapped in `llvm::IntrusiveRefCntPtr`) and only exposes an accessor returning `DiagnosticOptions &`. One would think this gives `CompilerInvocation` exclusive ownership of the object, but that's not the case: ```c++ void shareOwnership(CompilerInvocation &CI) { llvm::IntrusiveRefCntPtr<DiagnosticOptions> CoOwner = &CI.getDiagnosticOptions(); // ... } ``` This is a perfectly valid pattern that is being actually used in the codebase. I would like to ensure the ownership of `DiagnosticOptions` by `CompilerInvocation` is guaranteed to be exclusive. This can be leveraged for a copy-on-write optimization later on. This PR changes usages of `DiagnosticOptions` across `clang`, `clang-tools-extra` and `lldb` to not be intrusively reference-counted.
2025-05-22[clang] Use llvm::is_contained (NFC) (#140985)Kazu Hirata1-4/+4
2025-01-15[clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() ↵Boaz Brickner1-0/+14
(#123042) This would allow tools that don't use the real file system to use this function.
2024-11-21Reapply "[NFC] Explicitly pass a VFS when creating DiagnosticsEngine (#115852)"Kadir Cetinkaya1-1/+2
This reverts commit a1153cd6fedd4c906a9840987934ca4712e34cb2 with fixes to lldb breakages. Fixes https://github.com/llvm/llvm-project/issues/117145.
2024-11-21Revert "[NFC] Explicitly pass a VFS when creating DiagnosticsEngine (#115852)"Sylvestre Ledru1-2/+1
Reverted for causing: https://github.com/llvm/llvm-project/issues/117145 This reverts commit bdd10d9d249bd1c2a45e3de56a5accd97e953458.
2024-11-21[NFC] Explicitly pass a VFS when creating DiagnosticsEngine (#115852)kadir çetinkaya1-1/+2
Starting with 41e3919ded78d8870f7c95e9181c7f7e29aa3cc4 DiagnosticsEngine creation might perform IO. It was implicitly defaulting to getRealFileSystem. This patch makes it explicit by pushing the decision making to callers. It uses ambient VFS if one is available, and keeps using `getRealFileSystem` if there aren't any VFS.
2024-07-25[clang][CUDA] Assume unknown emission status for skipped function ↵kadir çetinkaya1-0/+5
definitions (#100124) Emission status seems to be only used by cuda/openmp/hip compiles, to figure out when to emit diagnostics. Current logic emits "uknown" when definition is missing, so i extended that to skipped-function-bodies as well.
2023-12-14[clang][modules] Deprecate module.map in favor of module.modulemap (#75142)Michael Spencer1-5/+5
This patch deprecates `module.map` in favor of `module.modulemap`, which has been the preferred form since 2014. The eventual goal is to remove support for `module.map` to reduce the number of stats Clang needs to do while searching for module map files. This patch touches a lot of files, but the majority of them are just renaming tests or references to the file in comments or documentation. The relevant files are: * lib/Lex/HeaderSearch.cpp * include/clang/Basic/DiagnosticGroups.td * include/clang/Basic/DiagnosticLexKinds.td
2023-08-08[Clang][Tooling] Accept preprocessed input filesJ. Ryan Stinnett1-0/+7
This restores the tooling library's ability to accept invocations that take a preprocessed file as the primary input. Regressed by https://reviews.llvm.org/D105695 Fixes https://github.com/llvm/llvm-project/issues/63941 Differential Revision: https://reviews.llvm.org/D157011
2023-03-17[clangd] Move standard options adaptor to CommandManglerDmitry Polukhin1-24/+9
There is a discrepancy between how clangd processes CDB loaded from JSON file on disk and pushed via LSP. Thus the same CDB pushed via LSP protocol may not work as expected. Some difference between these two paths is expected but we still need to insert driver mode and target from binary name and expand response files. Test Plan: check-clang-tools Differential Revision: https://reviews.llvm.org/D143436
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-01-09Move from llvm::makeArrayRef to ArrayRef deduction guides - clang/ partserge-sans-paille1-1/+1
This is a follow-up to https://reviews.llvm.org/D140896, split into several parts as it touches a lot of files. Differential Revision: https://reviews.llvm.org/D141139
2022-08-24[clang][tooling] Allow -cc1 arguments in ToolInvocationBen Langmuir1-0/+40
ToolInvocation is useful even if you already have a -cc1 invocation, since it provides a standard way to setup diagnostics, parse arguments, and handoff to a ToolAction. So teach it to support -cc1 commands by skipping the driver bits. Differential Revision: https://reviews.llvm.org/D132615
2021-10-08Move TargetRegistry.(h|cpp) from Support to MCReid Kleckner1-2/+2
This moves the registry higher in the LLVM library dependency stack. Every client of the target registry needs to link against MC anyway to actually use the target, so we might as well move this out of Support. This allows us to ensure that Support doesn't have includes from MC/*. Differential Revision: https://reviews.llvm.org/D111454
2021-09-23[clang][tooling] NFC: Refactor command-line diagnostic testsJan Svoboda1-34/+23
This patch uses a different command-line arguments to test `clang::tooling::ToolInvocation` that are not specific to Darwin. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D110160
2021-09-10[clang][tooling] Properly initialize DiagnosticsEngine for cc1 command-line ↵Jan Svoboda1-0/+76
construction In `ToolInvocation::run`, the driver -> cc1 command-line transformation uses `DiagnosticsEngine` that wasn't completely initialized. This patch ensures `ProcessWarningOptions(DiagnosticsEngine&, const DiagnosticOptions &)` is called. Depends on D108982. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D108974
2021-07-27[clang][tooling] Accept Clang invocations with multiple jobsJan Svoboda1-0/+102
When `-fno-integrated-as` is passed to the Clang driver (or set by default by a specific toolchain), it will construct an assembler job in addition to the cc1 job. Similarly, the `-fembed-bitcode` driver flag will create additional cc1 job that reads LLVM IR file. The Clang tooling library only cares about the job that reads a source file. Instead of relying on the fact that the client injected `-fsyntax-only` to the driver invocation to get a single `-cc1` invocation that reads the source file, this patch filters out such jobs from `Compilation` automatically and ignores the rest. This fixes a test failure in `ClangScanDeps/headerwithname.cpp` and `ClangScanDeps/headerwithnamefollowedbyinclude.cpp` on AIX reported here: https://reviews.llvm.org/D103461#2841918 and `clang-scan-deps` failures with `-fembed-bitcode`. Depends on D106788. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D105695
2021-04-06[clang][tooling] Create SourceManager for DiagnosticsEngine before ↵Jan Svoboda1-0/+37
command-line parsing In D84673, we started using `DiagnosticsEngine` during command-line parsing in more contexts. When using `ToolInvocation`, a custom `DiagnosticsConsumer` can be specified and it might expect `SourceManager` to be present on the emitted diagnostics. This patch ensures the `SourceManager` is set up in such scenarios. Test authored by Jordan Rupprecht. Reviewed By: rupprecht Differential Revision: https://reviews.llvm.org/D99414
2020-09-08getClangStripDependencyFileAdjuster(): Do not remove -M args when using MSVC ↵Shivanshu Goyal1-0/+34
cl driver MSVC's cl.exe has a few command line arguments which start with -M such as "-MD", "-MDd", "-MT", "-MTd", "-MP". These arguments are not dependency file generation related, and these arguments were being removed by getClangStripDependencyFileAdjuster() which was wrong. Differential revision: https://reviews.llvm.org/D86999
2020-08-03[clang][Tooling] Fix addTargetAndModeForProgramName to use correct flag namesKadir Cetinkaya1-11/+5
The logic was using incorrect flag versions. For example: - `-target=` can't be a prefix, it must be `--target=`. - `--driver-mode` can't appear on its own, value must be attached to it. While fixing those, also changes the append logic to make use of new `--target=X` format instead of the legacy `-target X` version. In addition to that makes use of the OPTTable instead of hardcoded strings to make sure helper also gets updated if clang's options are modified. Differential Revision: https://reviews.llvm.org/D85076
2020-04-27Strip -showIncludes in getClangStripDependencyFileAdjuster()Arthur Eubanks1-29/+6
Summary: Follow-up to https://reviews.llvm.org/D78836. Also consolidate some test cases. Reviewers: thakis Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D78939
2020-04-26[clangd] Strip /showIncludes in clangd compile commandsArthur Eubanks1-0/+56
In command lines with /showIncludes, clangd would output includes to stdout, breaking clients. Summary: Fixes https://github.com/clangd/clangd/issues/322. Reviewers: sammccall, kadircet Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D78836
2020-02-18[libTooling] Add option for `buildAST` to report diagnostics.Yitzhak Mandelbaum1-9/+19
Summary: Currently, `buildAST[WithArgs]` either succeeds or fails. This patch adds support for the caller to pass a `DiagnosticConsumer` to receive all relevant diagnostics. Reviewers: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D74763
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-4/+5
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-11-13[clang][Tooling] Filter flags that generate output in SyntaxOnlyAdjusterKadir Cetinkaya1-0/+34
Summary: Flags that generate output could result in failures when creating syntax only actions. This patch introduces initial logic for filtering out those. The first such flag is "save-temps", which saves intermediate files(bitcode, assembly, etc.) into a specified directory. Fixes https://github.com/clangd/clangd/issues/191 Reviewers: hokein Subscribers: ilya-biryukov, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70173
2019-08-30[Tooling] Migrated APIs that take ownership of objects to unique_ptrDmitri Gribenko1-47/+49
Subscribers: jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66960 llvm-svn: 370451
2019-08-14[Clang] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere1-8/+8
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-02[clang][ArgumentAdjusters] Do not add fsyntax-only if already existsKadir Cetinkaya1-0/+27
Reviewers: hokein Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64063 llvm-svn: 364904
2019-03-31Range-style std::find{,_if} -> llvm::find{,_if}. NFCFangrui Song1-4/+2
llvm-svn: 357359
2019-02-10Use llvm::is_contained. NFCFangrui Song1-1/+1
llvm-svn: 353635
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-18[tooling] Add a new argument adjuster for deleting plugin related command ↵Kadir Cetinkaya1-0/+31
line args Summary: Currently both clangd and clang-tidy makes use of this mechanism so putting it into tooling so that all tools can make use of it. Reviewers: ilya-biryukov, sammccall Subscribers: ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D56856 llvm-svn: 351531
2018-10-10Lift VFS from clang to llvm (NFC)Jonas Devlieghere1-12/+12
This patch moves the virtual file system form clang to llvm so it can be used by more projects. Concretely the patch: - Moves VirtualFileSystem.{h|cpp} from clang/Basic to llvm/Support. - Moves the corresponding unit test from clang to llvm. - Moves the vfs namespace from clang::vfs to llvm::vfs. - Formats the lines affected by this change, mostly this is the result of the added llvm namespace. RFC on the mailing list: http://lists.llvm.org/pipermail/llvm-dev/2018-October/126657.html Differential revision: https://reviews.llvm.org/D52783 llvm-svn: 344140
2018-04-30IWYU for llvm-config.h in clang. See r331124 for details.Nico Weber1-1/+0
llvm-svn: 331177
2018-04-27s/LLVM_ON_WIN32/_WIN32/, clangNico Weber1-2/+2
LLVM_ON_WIN32 is set exactly with MSVC and MinGW (but not Cygwin) in HandleLLVMOptions.cmake, which is where _WIN32 defined too. Just use the default macro instead of a reinvented one. See thread "Replacing LLVM_ON_WIN32 with just _WIN32" on llvm-dev and cfe-dev. No intended behavior change. llvm-svn: 331069
2018-03-19Updated a usage of createTemporaryFile that does not expect file to be created.Ilya Biryukov1-2/+2
Summary: This fixes a usage of createTemporaryFile in clang repo after a change in llvm repo. Reviewers: klimek, bkramer, krasimir, espindola, ilya-biryukov Reviewed By: ilya-biryukov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D36828 llvm-svn: 327852
2018-02-27Revert "[Tooling] [0/1] Refactor FrontendActionFactory::create() to return ↵Roman Lebedev1-59/+52
std::unique_ptr<>" This reverts commit rL326201 This broke gcc4.8 builds, compiler just segfaults:¬ http://lab.llvm.org:8011/builders/clang-atom-d525-fedora-rel/builds/14909¬ http://lab.llvm.org:8011/builders/clang-x86_64-linux-abi-test/builds/22673¬ llvm-svn: 326204
2018-02-27[Tooling] [0/1] Refactor FrontendActionFactory::create() to return ↵Roman Lebedev1-52/+59
std::unique_ptr<> Summary: Noticed during review of D41102. I'm not sure whether there are any principal reasons why it returns raw owning pointer, or it is just a old code that was not updated post-C++11. I'm not too sure what testing i should do, because `check-all` is not error clean here for some reason, but it does not //appear// asif those failures are related to these changes. This is clang part. Clang-tools-extra part is D43780. Reviewers: klimek, bkramer, alexfh, pcc Reviewed By: alexfh Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D43779 llvm-svn: 326201
2018-01-23[Tooling] Added a VFS parameter to ClangToolIlya Biryukov1-0/+18
Summary: The parameter overrides the underlying vfs used by ClangTool for filesystem operations. Patch by Vladimir Plyashkun. Reviewers: alexfh, ilya-biryukov Reviewed By: ilya-biryukov Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D41947 llvm-svn: 323195
2017-11-23Do not perform the analysis based warning if the warnings are ignoredOlivier Goffart1-0/+26
This saves some cycles when compiling with "-w". (Also fix a potential crash on invalid code for tools that tries to recover from some errors, because analysis might compute the CFG which crashes if the code contains invalid declaration. This does not happen normally with because we also don't perform these analysis if there was an error.) Differential Revision: https://reviews.llvm.org/D40242 llvm-svn: 318900
2017-11-17Fix skipping of flags in getClangStripDependencyFileAdjusterDave Lee1-0/+31
Summary: The ArgumentsAdjuster returned from `getClangStripDependencyFileAdjuster` will skip dependency flags, and also their associated values for those flags that take an argument. This change corrects the handling of the `-MD` and `-MMD` flags, which do not take an argument. Reviewers: saugustine, klimek, alexshap Reviewed By: alexshap Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D40024 llvm-svn: 318529
2017-06-09Remove 'Filename' parameter from BeginSourceFileAction.Richard Smith1-1/+1
No-one was using this, and it's not meaningful in general -- FrontendActions can be run on inputs that don't have a corresponding source file. The current frontend input can be obtained by asking the FrontendAction if any future action actually needs it. llvm-svn: 305045
2016-08-30Fix colored diagnostics from toolsOlivier Goffart1-0/+38
r271042 changed the way the diagnostic arguments are parsed. It assumes that the diagnostics options were already parsed by the "Driver". For tools using clang::Tooling, the diagnostics argument were not parsed. Differential Revision: https://reviews.llvm.org/D23837 llvm-svn: 280118
2016-07-18[NFC] Header cleanupMehdi Amini1-1/+2
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