aboutsummaryrefslogtreecommitdiff
path: root/clang/tools/driver/driver.cpp
AgeCommit message (Collapse)AuthorFilesLines
3 daysNFC: Clean up of IntrusiveRefCntPtr construction from raw pointers. (#151545)James Y Knight1-3/+1
Handles clang::DiagnosticsEngine and clang::DiagnosticIDs. For DiagnosticIDs, this mostly migrates from `new DiagnosticIDs` to convenience method `DiagnosticIDs::create()`. Part of cleanup https://github.com/llvm/llvm-project/issues/151026
2025-06-02[flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (#140556)Abid Qadeer1-1/+1
This PR add functionality to change `flang` command line using environment variable `FCC_OVERRIDE_OPTIONS`. It is quite similar to what `CCC_OVERRIDE_OPTIONS` does for clang. The `FCC_OVERRIDE_OPTIONS` seemed like the most obvious name to me but I am open to other ideas. The `applyOverrideOptions` now takes an extra argument that is the name of the environment variable. Previously `CCC_OVERRIDE_OPTIONS` was hardcoded.
2025-05-22Reapply "[clang] Remove intrusive reference count from `DiagnosticOptions` ↵Jan Svoboda1-6/+5
(#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-5/+6
(#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-6/+5
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-04-28[Clang] Add new -header-include-filtering=direct-per-file option (#137087)Bob Wilson1-1/+1
This adds a new filtering option to be used along with the -header-include-format=json option. The existing "only-direct-system" filtering option is missing some things: - It does not show module imports. - It does not show includes of non-system headers. This new "direct-per-file" filtering has a separate entry in the JSON output for each non-system source file, showing the direct includes and imports from that file. You can use this to see uses of non-system headers, and also find the paths through non-system headers that lead up to module imports and system headers. Modules are identified here by their modulemap files.
2025-04-23[Clang] Fix crash when -header-include-filtering is not specified (#136232)Bob Wilson1-0/+5
If you specify -header-include-format=json, the only filtering option currently supported is -header-include-filtering=only-direct-system. If you specify some other filtering option, Clang gives an error message. But, if you do not specify the filtering option at all, Clang crashes when producing the error message, since it tries to get the value of the unused option.
2025-02-06[clang] Stop parsing warning suppression mappings in driver (#125722)kadir çetinkaya1-0/+4
This gets rid of some extra IO from driver startup, and possiblity of emitting warnings twice.
2025-01-10[Support] Reduce globaal variable overhead after #121663Fangrui Song1-1/+1
* Construct frequently-accessed TimerLock/DefaultTimerGroup early to reduce overhead. * Rename `aquireDefaultGroup` to `acquireTimerGlobals` and restore ManagedStatic::claim. https://reviews.llvm.org/D76099 * Drop mtg::. We use internal linkage, so mtg:: is unneeded and might mislead users. In addition, llvm/ code almost never introduces a named namespace not in llvm::. Drop mtg::. * Replace some unique_ptr with optional to reduce overhead. * Switch to `functionName()`. * Simplify `llvm::initTimerOptions` and `TimerGroup::constructForStatistics()` Pull Request: https://github.com/llvm/llvm-project/pull/122429
2025-01-08Clean up -Wdangling-assignment-gsl in clang and mlirBenjamin Kramer1-3/+5
These are triggering after b037bceef6a40c5c00c1f67cc5a334e2c4e5e041.
2024-11-13Reapply "[clang] Introduce diagnostics suppression mappings (#112517)"Kadir Cetinkaya1-2/+5
This reverts commit 5f140ba54794fe6ca379362b133eb27780e363d7.
2024-11-12Revert "[clang] Introduce diagnostics suppression mappings (#112517)"Kadir Cetinkaya1-5/+2
This reverts commit 12e3ed8de8c6063b15916b3faf67c8c9cd17df1f. This reverts commit 41e3919ded78d8870f7c95e9181c7f7e29aa3cc4. There are some buildbot breakages in https://lab.llvm.org/buildbot/#/builders/18/builds/6832.
2024-11-12[clang] Introduce diagnostics suppression mappings (#112517)kadir çetinkaya1-2/+5
This implements https://discourse.llvm.org/t/rfc-add-support-for-controlling-diagnostics-severities-at-file-level-granularity-through-command-line/81292. Users now can suppress warnings for certain headers by providing a mapping with globs, a sample file looks like: ``` [unused] src:* src:*clang/*=emit ``` This will suppress warnings from `-Wunused` group in all files that aren't under `clang/` directory. This mapping file can be passed to clang via `--warning-suppression-mappings=foo.txt`. At a high level, mapping file is stored in DiagnosticOptions and then processed with rest of the warning flags when creating a DiagnosticsEngine. This is a functor that uses SpecialCaseLists underneath to match against globs coming from the mappings file. This implies processing warning options now performs IO, relevant interfaces are updated to take in a VFS, falling back to RealFileSystem when one is not available.
2024-09-06[NFC] Add explicit #include llvm-config.h where its macros are used, clang ↵Daniil Fukalov1-0/+2
part. (#107301) (this is clang related part) Without these explicit includes, removing other headers, who implicitly include llvm-config.h, may have non-trivial side effects. For example, `clagd` may report even `llvm-config.h` as "no used" in case it defines a macro, that is explicitly used with #ifdef. It is actually amplified with different build configs which use different set of macros.
2024-03-15[clang] Move CCC_OVERRIDE_OPTIONS implementation to Driver (#85425)Dave Lee1-134/+7
Move CCC_OVERRIDE_OPTIONS support to clangDriver so that it may be used outside of the clang driver binary. The override functionality will be used in LLDB, to apply adjustments to ClangImporter flags. This will be useful as an escape hatch when there are issues that can be fixed by adding or removing clang flags. The only thing changed is the name, from `ApplyQAOverride` to `applyOverrideOptions`.
2024-02-28[Driver] Unify InstalledDir and Dir (#80527)Fangrui Song1-23/+0
`Driver::ClangExecutable` is derived from: * (-canonical-prefixes default): `realpath` on the executable path * (-no-canonical-prefixes) argv[0] (consult PATH if argv[0] is a word) `Dir` and `ResourceDir` are derived from `ClangExecutable`. Both variables are used to derive certain include and library paths. `InstalledDir` is a related concept used to derive certain other paths. `InstalledDir` is weird in the -canonical-prefixes mode: Clang calls `make_absolute` but does not follow symlinks (FIXME from 9ade6a9a747c49383ac747bd8ffaa6a0beaef71c). This causes some search and library paths to be mix-and-matched. The "Do a PATH lookup, if there are no directory components." logic makes things worse. `InstalledDir` is different when you invoke it via `PATH`: ``` % which clang /usr/bin/clang % clang -v |& grep InstalledDir InstalledDir: /usr/bin % /usr/lib/llvm-16/bin/clang -v |& grep InstalledDir InstalledDir: /usr/lib/llvm-16/bin ``` I believe `InstalledDir` was a partial solution to `-no-canonical-prefixes` and should be eventually removed. This patch removes `SetInstallDir` and relies on Driver::Driver to set `InstalledDir` to `Dir`. The behavior for regular file `clang` or `-no-canonical-prefixes` is unchanged. If a user creates a symlink to the regular file `clang` and uses the default `-canonical-prefixes`, they now consistently get search and library paths relative to the regular file `clang`, not mix-and-match paths. If a user creates a symlink to the regular file `clang` and replaces some directorys from the actual installation, they should change the symlink to a wrapper that calls the underlying clang with `-no-canonical-prefixes`.
2024-02-15[clang][driver] Add missing integrated tool option in error message, NFC ↵Cyndy Ishida1-2/+3
(#81926)
2024-01-12[clang] Use SmallString::operator std::string() (NFC)Kazu Hirata1-1/+1
2024-01-11[llvm-driver] Fix usage of `InitLLVM` on Windows (#76306)Alexandre Ganea1-2/+0
Previously, some tools such as `clang` or `lld` which require strict order for certain command-line options, such as `clang -cc1` or `lld -flavor`, would not longer work on Windows, when these tools were linked as part of `llvm-driver`. This was caused by `InitLLVM` which was part of the `*_main()` function of these tools, which in turn calls `windows::GetCommandLineArguments`. That function completly replaces argc/argv by new UTF-8 contents, so any ajustements to argc/argv made by `llvm-driver` prior to calling these tools was reset. `InitLLVM` is now called by the `llvm-driver`. Any tool that participates in (or is part of) the `llvm-driver` doesn't call `InitLLVM` anymore.
2023-12-13[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)Kazu Hirata1-2/+2
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-08-15[clang] Fix f7f3e68419 (NFC)Dave Lee1-1/+1
2023-08-15[clang] Fix CCC_OVERRIDE_OPTIONS docstring to say "space separated" (NFC)Dave Lee1-3/+3
As well as a couple other minor docstring corrections.
2023-03-16[Driver] Allow to collect `-save-stats` data to a file specified in the ↵Volodymyr Sapsai1-0/+3
environment variable. Using two environment variables `CC_PRINT_INTERNAL_STAT` and `CC_PRINT_INTERNAL_STAT_FILE` to work like `CC_PRINT_PROC_STAT`. The purpose of the change is to allow collecting the internal stats without modifying the build scripts. Write all stats to a single file to simplify aggregating the data. Differential Revision: https://reviews.llvm.org/D144981
2023-03-13[clang][deps] Handle response files in dep scannerBen Langmuir1-41/+3
Extract the code the driver uses to expand response files and reuse it in the dependency scanner. rdar://106155880 Differential Revision: https://reviews.llvm.org/D145838
2023-02-10[Driver] Stop stack use after freeAlex Brachet1-1/+1
In reality this would have always been fine because main's stack frame will always be live when another thread is executing the cc1_reproducer_main. But ASan and HWASan were upset
2023-02-10[llvm-driver] Reinvoke clang as described by llvm driver extra argsAlex Brachet1-11/+25
Differential Revision: https://reviews.llvm.org/D137800
2023-02-10[llvm-driver] Pass extra arguments to toolsAlex Brachet1-1/+2
Differential Revision: https://reviews.llvm.org/D137799
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-14[clang] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-6/+7
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-09Move from llvm::makeArrayRef to ArrayRef deduction guides - clang/ partserge-sans-paille1-5/+4
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
2023-01-05Save the result of getenv() to a stringAkira Hatanaka1-28/+35
The result has to be saved to a string as the result might be overwritten by subsequent calls to getenv. https://pubs.opengroup.org/onlinepubs/009696899/functions/getenv.html See the discussion here: https://reviews.llvm.org/D137996#4029305
2022-12-17std::optional::value => operator*/operator->Fangrui Song1-2/+2
value() has undesired exception checking semantics and calls __throw_bad_optional_access in libc++. Moreover, the API is unavailable without _LIBCPP_NO_EXCEPTIONS on older Mach-O platforms (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). This fixes clang.
2022-12-07Add support for a backdoor driver option that enables emitting headerAkira Hatanaka1-20/+54
usage information in JSON to a file Each line in the file is a JSON object that has the name of the main source file followed by the list of system header files included directly or indirectly from that file. For example: {"source":"/tmp/foo.c", "includes":["/usr/include/stdio.h", "/usr/include/stdlib.h"]} To reduce the amount of data written to the file, only the system headers that are directly included from a non-system header file are recorded. In order to emit the header information in JSON, it is necessary to set the following environment variables: CC_PRINT_HEADERS_FORMAT=json CC_PRINT_HEADERS_FILTERING=only-direct-system The following combination is equivalent to setting CC_PRINT_HEADERS=1: CC_PRINT_HEADERS_FORMAT=textual CC_PRINT_HEADERS_FILTERING=none Differential Revision: https://reviews.llvm.org/D137996
2022-12-06Process: convert Optional to std::optionalKrzysztof Parzyszek1-2/+3
This applies to GetEnv and FindInEnvPath.
2022-12-03[clang] Use std::nullopt instead of None (NFC)Kazu Hirata1-1/+1
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to 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-03[Clang] Check for response file existence prior to check for recursionSerge Pavlov1-1/+1
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-2/+9
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-9/+2
This reverts commit 17eb198de934eced784e16ec15e020a574ba07e1. Reverted for investigation, because ClangDriverTests failed on some builders.
2022-10-29Handle errors in expansion of response filesSerge Pavlov1-2/+9
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-09-29[Support] Class for response file expansion (NFC)Serge Pavlov1-4/+4
Functions that implement expansion of response and config files depend on many options, which are passes as arguments. Extending the expansion requires new options, it in turn causes changing calls in various places making them even more bulky. This change introduces a class ExpansionContext, which represents set of options that control the expansion. Its methods implements expansion of responce files including config files. It makes extending the expansion easier. No functional changes. Differential Revision: https://reviews.llvm.org/D132379
2022-09-28Revert "[Support] Class for response file expansion (NFC)"Serge Pavlov1-4/+4
This reverts commit 6e491c48d6b9cadcc5b77f730dd83a1448197329. There are missed changes in flang.
2022-09-28[Support] Class for response file expansion (NFC)Serge Pavlov1-4/+4
Functions that implement expansion of response and config files depend on many options, which are passes as arguments. Extending the expansion requires new options, it in turn causes changing calls in various places making them even more bulky. This change introduces a class ExpansionContext, which represents set of options that control the expansion. Its methods implements expansion of responce files including config files. It makes extending the expansion easier. No functional changes. Differential Revision: https://reviews.llvm.org/D132379
2022-07-13[clang] Use value instead of getValue (NFC)Kazu Hirata1-2/+2
2022-06-25[clang] Don't use Optional::hasValue (NFC)Kazu Hirata1-2/+2
This patch replaces Optional::hasValue with the implicit cast to bool in conditionals only.
2022-06-25Revert "Don't use Optional::hasValue (NFC)"Kazu Hirata1-4/+4
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25Don't use Optional::hasValue (NFC)Kazu Hirata1-4/+4
2022-06-06LLVM Driver Multicall toolChris Bieneman1-1/+1
This patch adds an llvm-driver multicall tool that can combine multiple LLVM-based tools. The build infrastructure is enabled for a tool by adding the GENERATE_DRIVER option to the add_llvm_executable CMake call, and changing the tool's main function to a canonicalized tool_name_main format (i.e. llvm_ar_main, clang_main, etc...). As currently implemented llvm-driver contains dsymutil, llvm-ar, llvm-cxxfilt, llvm-objcopy, and clang (if clang is included in the build). llvm-driver can be enabled from builds by setting LLVM_TOOL_LLVM_DRIVER_BUILD=On. There are several limitations in the current implementation, which can be addressed in subsequent patches: (1) the multicall binary cannot currently properly handle multi-dispatch tools. This means symlinking llvm-ranlib to llvm-driver will not properly result in llvm-ar's main being called. (2) the multicall binary cannot be comprised of tools containing conflicting cl::opt options as the global cl::opt option list cannot contain duplicates. These limitations can be addressed in subsequent patches. Differential revision: https://reviews.llvm.org/D109977
2022-06-01Fix potentially uninitialized memoryMikhail Goncharov1-3/+6
For https://github.com/llvm/llvm-project/commit/7d76d6095880f34914d85d876b260cc4a4ea640d
2022-05-31[Clang] Extend -gen-reproducer flagAlex Brachet1-21/+34
`-gen-reproducer` causes crash reproduction to be emitted even when clang didn't crash, and now can optionally take an argument of never, on-crash (default), on-error and always. Differential revision: https://reviews.llvm.org/D120201
2022-05-27Revert "[Clang] Extend -gen-reproducer flag"Alex Brachet1-34/+21
This reverts commit 684c080108766b4f112f172fed4a49059484614d.