aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Driver/ToolChainTest.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-05-22Reapply "[clang] Remove intrusive reference count from `DiagnosticOptions` ↵Jan Svoboda1-35/+36
(#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-36/+35
(#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-35/+36
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-16[clang] Use llvm::replace (NFC) (#140264)Kazu Hirata1-9/+9
2025-04-28[clang] Hide the `TargetOptions` pointer from `CompilerInvocation` (#106271)Jan Svoboda1-2/+1
This PR hides the reference-counted pointer that holds `TargetOptions` from the public API of `CompilerInvocation`. This gives `CompilerInvocation` an exclusive control over the lifetime of this member, which will eventually be leveraged to implement a copy-on-write behavior. There are two clients that currently share ownership of that pointer: * `TargetInfo` - This was refactored to hold a non-owning reference to `TargetOptions`. The options object is typically owned by the `CompilerInvocation` or by the new `CompilerInstance::AuxTargetOpts` for the auxiliary target. This needed a bit of care in `ASTUnit::Parse()` to keep the `CompilerInvocation` alive. * `clangd::PreambleData` - This was refactored to exclusively own the `TargetOptions` that get moved out of the `CompilerInvocation`.
2025-02-04[clang] UEFI targets must use CodeView. (#124660)Prabhuk1-0/+17
2024-11-21Reapply "[NFC] Explicitly pass a VFS when creating DiagnosticsEngine (#115852)"Kadir Cetinkaya1-1/+1
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-1/+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/+1
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-09-20Reland "[Driver] Add toolchain for X86_64 UEFI target" (#109364)Prabhuk1-0/+21
Reverts llvm/llvm-project#109340 Addressing the failed MAC Clang Driver test as part of this reland.
2024-09-20Revert "[SystemZ][z/OS] Propagate IsText parameter to open text files as ↵Abhina Sreeskantharajan1-1/+1
text (#107906)" This reverts commit edf3b277a5f2ebe144827ed47463c22743cac5f9.
2024-09-19Revert "[Driver] Add toolchain for X86_64 UEFI target" (#109340)Prabhuk1-21/+0
Reverts llvm/llvm-project#76838 Appears to be causing failures in MAC builders. First reverting the patch and will investigate after.
2024-09-19[Driver] Add toolchain for X86_64 UEFI target (#76838)Prabhuk1-0/+21
Introduce changes necessary for UEFI X86_64 target Clang driver. Addressed the review comments originally suggested in Phabricator. Differential Revision: https://reviews.llvm.org/D159541
2024-09-19[SystemZ][z/OS] Propagate IsText parameter to open text files as text (#107906)Abhina Sree1-1/+1
This patch adds an IsText parameter to the following functions openFileForRead, getBufferForFile, getBufferForFileImpl and determines whether a file is text by querying the file tag on z/OS. The default is set to OF_Text instead of OF_None, this change in value does not affect any other platforms other than z/OS.
2023-12-13[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)Kazu Hirata1-1/+1
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-09-27[Driver] Fix VFSGnuLibcxxPathNoSysroot test with DEFAULT_SYSROOTSam McCall1-1/+2
2023-09-22[Driver] Fix detection of libc++ with empty sysroot. (#66947)Sam McCall1-0/+48
b1e3cd1d79443603dc003441e07cdd8d30bb7f26 dropped the leading slash here, presumably unintentionally. (I don't understand Driver well enough to know how/where this is supposed to be tested, but it broke clangd on any project that uses the system-installed -stdlib=libc++ on a standard debian install)
2023-08-16[Driver][unittest] Unbreak ToolChainTest.cpp compilation with -WerrorRainer Orth1-2/+1
D157275 broke some buildbots that run with -Werror: https://lab.llvm.org/buildbot#builders/36/builds/36604 https://lab.llvm.org/buildbot#builders/57/builds/29201 Avoid this by using an overlong line rather than appeasing `clang-format`.
2023-08-16[Driver] Select newest GCC installation on SolarisRainer Orth1-0/+149
As described in Issue #53709 <https://github.com/llvm/llvm-project/issues/53709>, since 28d58d8fe2094af6902dee7b4d68ec30a3e9d737 <https://reviews.llvm.org/rG28d58d8fe2094af6902dee7b4d68ec30a3e9d737> `clang` doesn't find the latest of several parallel GCC installations on Solaris, but only the first in directory order, which is pretty random. This patch sorts GCC installations in reverse version order so the latest is picked. Tested on `sparcv9-sun-solaris2.11`, `amd64-pc-solaris2.11`, and `x86_64-pc-linux-gnu`. Differential Revision: https://reviews.llvm.org/D157275
2023-07-12[clang][clangd] Don't crash/assert on -gsplit-dwarf=single without outputDmitry Polukhin1-0/+10
The crash happens in clang::driver::tools::SplitDebugName when Output is InputInfo::Nothing. It doesn't happen with standalone clang driver because output is created in Driver::BuildJobsForActionNoCache. Example backtrace: ``` * thread #1, name = 'clangd', stop reason = hit program assert * frame #0: 0x00007ffff5c4eacf libc.so.6`raise + 271 frame #1: 0x00007ffff5c21ea5 libc.so.6`abort + 295 frame #2: 0x00007ffff5c21d79 libc.so.6`__assert_fail_base.cold.0 + 15 frame #3: 0x00007ffff5c47426 libc.so.6`__assert_fail + 70 frame #4: 0x000055555dc0923c clangd`clang::driver::InputInfo::getFilename(this=0x00007fffffff9398) const at InputInfo.h:84:5 frame #5: 0x000055555dcd0d8d clangd`clang::driver::tools::SplitDebugName(JA=0x000055555f6c6a50, Args=0x000055555f6d0b80, Input=0x00007fffffff9678, Output=0x00007fffffff9398) at CommonArgs.cpp:1275:40 frame #6: 0x000055555dc955a5 clangd`clang::driver::tools::Clang::ConstructJob(this=0x000055555f6c69d0, C=0x000055555f6c64a0, JA=0x000055555f6c6a50, Output=0x00007fffffff9398, Inputs=0x00007fffffff9668, Args=0x000055555f6d0b80, LinkingOutput=0x0000000000000000) const at Clang.cpp:5690:33 frame #7: 0x000055555dbf6b54 clangd`clang::driver::Driver::BuildJobsForActionNoCache(this=0x00007fffffffb5e0, C=0x000055555f6c64a0, A=0x000055555f6c6a50, TC=0x000055555f6c4be0, BoundArch=(Data = 0x0000000000000000, Length = 0), AtTopLevel=true, MultipleArchs=false, LinkingOutput=0x0000000000000000, CachedResults=size=1, TargetDeviceOffloadKind=OFK_None) const at Driver.cpp:5618:10 frame #8: 0x000055555dbf4ef0 clangd`clang::driver::Driver::BuildJobsForAction(this=0x00007fffffffb5e0, C=0x000055555f6c64a0, A=0x000055555f6c6a50, TC=0x000055555f6c4be0, BoundArch=(Data = 0x0000000000000000, Length = 0), AtTopLevel=true, MultipleArchs=false, LinkingOutput=0x0000000000000000, CachedResults=size=1, TargetDeviceOffloadKind=OFK_None) const at Driver.cpp:5306:26 frame #9: 0x000055555dbeb590 clangd`clang::driver::Driver::BuildJobs(this=0x00007fffffffb5e0, C=0x000055555f6c64a0) const at Driver.cpp:4844:5 frame #10: 0x000055555dbe6b0f clangd`clang::driver::Driver::BuildCompilation(this=0x00007fffffffb5e0, ArgList=ArrayRef<const char *> @ 0x00007fffffffb268) at Driver.cpp:1496:3 frame #11: 0x000055555b0cc0d9 clangd`clang::createInvocation(ArgList=ArrayRef<const char *> @ 0x00007fffffffbb38, Opts=CreateInvocationOptions @ 0x00007fffffffbb90) at CreateInvocationFromCommandLine.cpp:53:52 frame #12: 0x000055555b378e7b clangd`clang::clangd::buildCompilerInvocation(Inputs=0x00007fffffffca58, D=0x00007fffffffc158, CC1Args=size=0) at Compiler.cpp:116:44 frame #13: 0x000055555895a6c8 clangd`clang::clangd::(anonymous namespace)::Checker::buildInvocation(this=0x00007fffffffc760, TFS=0x00007fffffffe570, Contents= Has Value=false ) at Check.cpp:212:9 frame #14: 0x0000555558959cec clangd`clang::clangd::check(File=(Data = "build/test.cpp", Length = 64), TFS=0x00007fffffffe570, Opts=0x00007fffffffe600) at Check.cpp:486:34 frame #15: 0x000055555892164a clangd`main(argc=4, argv=0x00007fffffffecd8) at ClangdMain.cpp:993:12 frame #16: 0x00007ffff5c3ad85 libc.so.6`__libc_start_main + 229 frame #17: 0x00005555585bbe9e clangd`_start + 46 ``` Test Plan: ninja ClangDriverTests && tools/clang/unittests/Driver/ClangDriverTests Differential Revision: https://reviews.llvm.org/D154602
2023-01-26[unittests] Use GTEST_SKIP() instead of return when appropriatePaul Robinson1-1/+1
Basically NFC: A TEST/TEST_F/etc that bails out early (usually because setup failed or some other runtime condition wasn't met) generally should use GTEST_SKIP() to report its status correctly, unless it takes steps to report another status (e.g., FAIL()).
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-11-16[Driver] Enable nested configuration filesSerge Pavlov1-0/+52
Users may partition parameters specified by configuration file and put different groups into separate files. These files are inserted into the main file using constructs `@file`. Relative file names in it are resolved relative to the including configuration file and this is not convenient in some cases. A configuration file, which resides in system directory, may need to include a file with user-defined parameters and still provide default definitions if such file is absent. To solve such problems, the option `--config=` is allowed inside configuration files. Like `@file` it results in insertion of command-line arguments but the algorithm of file search is different and allows overriding system definitions with user ones. Differential Revision: https://reviews.llvm.org/D136354
2022-11-03[Clang] Check for response file existence prior to check for recursionSerge Pavlov1-3/+4
As now errors in file operation are handled, check for file existence must be done prior to check for recursion, otherwise reported errors are misleading. Differential Revision: https://reviews.llvm.org/D136090
2022-10-31Handle errors in expansion of response filesSerge Pavlov1-0/+201
Previously an error raised during an expansion of response files (including configuration files) was ignored and only the fact of its presence was reported to the user with generic error messages. This made it difficult to analyze problems. For example, if a configuration file tried to read an inexistent file, the error message said that 'configuration file cannot be found', which is wrong and misleading. This change enhances handling errors in the expansion so that users could get more informative error messages. Differential Revision: https://reviews.llvm.org/D136090
2022-10-30Revert "Handle errors in expansion of response files"Serge Pavlov1-200/+0
This reverts commit 17eb198de934eced784e16ec15e020a574ba07e1. Reverted for investigation, because ClangDriverTests failed on some builders.
2022-10-29Handle errors in expansion of response filesSerge Pavlov1-0/+200
Previously an error raised during an expansion of response files (including configuration files) was ignored and only the fact of its presence was reported to the user with generic error messages. This made it difficult to analyze problems. For example, if a configuration file tried to read an inexistent file, the error message said that 'configuration file cannot be found', which is wrong and misleading. This change enhances handling errors in the expansion so that users could get more informative error messages. Differential Revision: https://reviews.llvm.org/D136090
2022-10-26[clang][driver] Remove dynamic gcc-toolset/devtoolset logicTimm Bäder1-91/+0
This breaks when the newest available devtoolset directory is not a complete toolset: https://github.com/llvm/llvm-project/issues/57843 Remove this again in favor or just adding the two new directories for devtoolset/gcc-toolset 12. This reverts commit 35aaf548237a4f213ba9d95de53b33c5ce1eadce. This reverts commit 9f97720268911abae2ad9d90e270358db234a1c1. Fixes https://github.com/llvm/llvm-project/issues/57843 Differential Revision: https://reviews.llvm.org/D136435
2022-09-09[Clang] Use virtual FS in processing config filesSerge Pavlov1-0/+57
Clang has support of virtual file system for the purpose of testing, but treatment of config files did not use it. This change enables VFS in it as well. Differential Revision: https://reviews.llvm.org/D132867
2022-09-09Revert "[Clang] Use virtual FS in processing config files"Serge Pavlov1-57/+0
This reverts commit 9424497e43aff088e014d65fd952ec557e28e6cf. Some buildbots failed, reverted for investigation.
2022-09-09[Clang] Use virtual FS in processing config filesSerge Pavlov1-0/+57
Clang has support of virtual file system for the purpose of testing, but treatment of config files did not use it. This change enables VFS in it as well. Differential Revision: https://reviews.llvm.org/D132867
2022-08-18[NFC] Move DXC driver testsChris Bieneman1-209/+3
The DXC driver tests don't really belong mixed in with the toolchain tests. This pulls them out to their own file and moves the SimpleDiagnosticConsumer into a header so it can be used by both DXC and toolchain tests. fast-forwarded.
2022-08-18[HLSL] Set main as default entry.Xiang Li1-0/+29
When there's no -E option, use main as entry function. Reviewed By: beanz Differential Revision: https://reviews.llvm.org/D124753
2022-07-16[test] Fix memory leak in validateTargetProfileVitaly Buka1-43/+48
Unfortunatly fixing leak expose use-after-free if delete more then one Compilation for the same Driver, so I am changing validateTargetProfile to create own Driver each time. The test was added by D122865.
2022-07-16[test] Don't leak DerivedArgList in testVitaly Buka1-6/+10
2022-06-13[clang][driver] fix to correctly set devtoolset on RHELQuinn Pham1-10/+10
This patch correctly sets the devtoolset on RHEL. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D127310
2022-06-09[clang][tests] Add missing compiler nameTimm Bäder1-2/+2
The driver stripts the first argument. Without the compiler name, the test depends on whether GCC_INSTALL_PREFIX is set or not. See https://reviews.llvm.org/D125862
2022-06-03[clang][driver] Dynamically select gcc-toolset/devtoolsetTimm Bäder1-0/+91
Instead of adding all devtoolset and gcc-toolset prefixes to the list of prefixes, just scan the /opt/rh/ directory for the one with the highest version number and only add that one. Differential Revision: https://reviews.llvm.org/D125862
2022-05-31[HLSL][clang][Driver] Parse target profile early to update Driver::TargetTriple.Xiang Li1-104/+55
This is to avoid err_target_unknown_abi which is caused by use default TargetTriple instead of shader model target triple. Reviewed By: beanz Differential Revision: https://reviews.llvm.org/D125585
2022-05-23Revert "[clang][driver] Dynamically select gcc-toolset/devtoolset version"Timm Bäder1-88/+0
This reverts commit 8717b492dfcd12d6387543a2f8322e0cf9059982. The new unittest fails on Windows buildbots, e.g. https://lab.llvm.org/buildbot/#/builders/119/builds/8647
2022-05-23[clang][driver] Dynamically select gcc-toolset/devtoolset versionTimm Bäder1-0/+88
And pick the highest one, instead of adding all possibilities to the prefixes. Differential Revision: https://reviews.llvm.org/D125862
2022-04-30ClangDriverTests:ToolChainTest.cpp: Fix warnings. [-Wsign-compare]NAKAMURA Takumi1-5/+5
EXPECT_EQ(num,num) is aware of signedness, even if rhs is a constant.
2022-04-29[HLSL][clang][Driver] Support validator version command line option.python3kgae1-25/+129
The DXIL validator version option(/validator-version) decide the validator version when compile hlsl. The format is major.minor like 1.0. In normal case, the value of validator version should be got from DXIL validator. Before we got DXIL validator ready for llvm/main, DXIL validator version option is added first to set validator version. It will affect code generation for DXIL, so it is treated as a code gen option. A new member std::string DxilValidatorVersion is added to clang::CodeGenOptions. Then CGHLSLRuntime is added to clang::CodeGenModule. It is used to translate clang::CodeGenOptions::DxilValidatorVersion into a ModuleFlag under key "dx.valver" at end of clang code generation. Reviewed By: beanz Differential Revision: https://reviews.llvm.org/D123884
2022-04-15Blind stab in the dark to fix a bot failureChris Bieneman1-0/+2
*fingers crossed*
2022-04-15[HLSL][clang][Driver] Support target profile command line option.Xiang Li1-0/+143
The target profile option(/T) decide the shader model when compile hlsl. The format is shaderKind_major_minor like ps_6_1. The shader model is saved as llvm::Triple is clang/llvm like dxil-unknown-shadermodel6.1-hull. The main job to support the option is translating ps_6_1 into shadermodel6.1-pixel. That is done inside tryParseProfile at HLSL.cpp. To integrate the option into clang Driver, a new DriverMode DxcMode is created. When DxcMode is enabled, OSType for TargetTriple will be forced into Triple::ShaderModel. And new ToolChain HLSLToolChain will be created when OSType is Triple::ShaderModel. In HLSLToolChain, ComputeEffectiveClangTriple is overridden to call tryParseProfile when targetProfile option is set. To make test work, Fo option is added and .hlsl is added for active -xhlsl. Reviewed By: beanz Differential Revision: https://reviews.llvm.org/D122865 Patch by: Xiang Li <python3kgae@outlook.com>
2021-12-09[clang] Fix a misadjusted path style comparison in a unittestMartin Storsjö1-1/+1
This was changed incorrectly by accident in 99023627010bbfefb71e25a2b4d056de1cbd354e. Differential Revision: https://reviews.llvm.org/D113254
2021-10-29Support: Use sys::path::is_style_{posix,windows}() in a few placesDuncan P. N. Exon Smith1-9/+6
Use the new sys::path::is_style_posix() and is_style_windows() in a few places that need to detect the system's native path style. In llvm/lib/Support/Path.cpp, this patch removes most uses of the private `real_style()`, where is_style_posix() and is_style_windows() are just a little tidier. Elsewhere, this removes `_WIN32` macro checks. Added a FIXME to a FileManagerTest that seemed fishy, but maintained the existing behaviour. Differential Revision: https://reviews.llvm.org/D112289
2021-10-08Move TargetRegistry.(h|cpp) from Support to MCReid Kleckner1-1/+1
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-07[clang][Driver] Pick the last --driver-mode in case of multiple onesKadir Cetinkaya1-0/+7
This was an accidental behaviour change in D106789 and this patch restores it back to original state. Differential Revision: https://reviews.llvm.org/D109361
2021-07-27[clang][driver] NFC: Expose InputInfo in Job instead of plain filenamesJan Svoboda1-2/+2
This patch exposes `InputInfo` in `Job` instead of plain filenames. This is useful in a follow-up patch that uses this to recognize `-cc1` commands interesting for Clang tooling. Depends on D106787. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D106788