aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Driver/Compilation.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-10[Clang] [NFC] Inline static helper function in `Compilation.cpp` (#152875)Thibault Monnier1-6/+1
This PR inlines the static `InputsOk` function in clang `Compilation.cpp` driver, because it was just a simple function call and was called only once. In addition, inlining it allows removing the double negation.
2025-01-06[Driver][SYCL] Add initial SYCL offload compilation support (#117268)Michael Toguchi1-4/+5
Introduces the SYCL based toolchain and initial toolchain construction when using the '-fsycl' option. This option will enable SYCL based offloading, creating a SPIR-V based IR file packaged into the compiled host object. This includes early support for creating the host/device object using the new offloading model. The device object is created using the spir64-unknown-unknown target triple. New/Updated Options: -fsycl Enables SYCL offloading for host and device -fsycl-device-only Enables device only compilation for SYCL -fsycl-host-only Enables host only compilation for SYCL RFC Reference: https://discourse.llvm.org/t/rfc-sycl-driver-enhancements/74092 This is a reland of: https://github.com/llvm/llvm-project/pull/107493
2024-11-15[Driver] Remove unused includes (NFC) (#116316)Kazu Hirata1-3/+0
Identified with misc-include-cleaner.
2024-11-15Revert "[Driver][SYCL] Add initial SYCL offload compilation support" (#116381)Aaron Ballman1-5/+4
Reverts llvm/llvm-project#107493 Failing bots include: https://lab.llvm.org/buildbot/#/builders/190/builds/9546 https://lab.llvm.org/buildbot/#/builders/46/builds/7938
2024-11-15[Driver][SYCL] Add initial SYCL offload compilation support (#107493)Michael Toguchi1-4/+5
Introduces the SYCL based toolchain and initial toolchain construction when using the '-fsycl' option. This option will enable SYCL based offloading, creating a SPIR-V based IR file packaged into the compiled host object. This includes early support for creating the host/device object using the new offloading model. The device object is created using the spir64-unknown-unknown target triple. New/Updated Options: -fsycl Enables SYCL offloading for host and device -fsycl-device-only Enables device only compilation for SYCL -fsycl-host-only Enables host only compilation for SYCL RFC Reference: https://discourse.llvm.org/t/rfc-sycl-driver-enhancements/74092
2024-11-12Revert "[clang][flang] Support -time in both clang and flang"Tarun Prabhu1-20/+0
Reverts llvm/llvm-project#109165 This created a buildbot failure on [Fuchsia](https://lab.llvm.org/buildbot/#/builders/11/builds/8080).
2024-11-12[clang][flang] Support -time in both clang and flangTarun Prabhu1-0/+20
The -time option prints timing information for the subcommands (compiler, linker) in a format similar to that used by gcc/gfortran. This partially addresses requests from #89888
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.
2022-12-08[clang] Don't including None.h (NFC)Kazu Hirata1-1/+0
These source files no longer use None, so they do not need to include None.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
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-12-01Support: Convert Program APIs to std::optionalMatt Arsenault1-1/+1
2022-09-03[clang] Qualify auto in range-based for loops (NFC)Kazu Hirata1-1/+1
2022-08-20Use range-based for loops (NFC)Kazu Hirata1-3/+3
2022-06-13[clang][driver] Introduce new -fdriver-only flagJan Svoboda1-3/+8
This patch introduces the new -fdriver-only flag which instructs Clang to only execute the driver logic without running individual jobs. In a way, this is very similar to -###, with the following differences: * it doesn't automatically print all jobs, * it doesn't avoid side effects (e.g. it will generate compilation database when -MJ is specified). This flag will be useful in testing D121997. Reviewed By: dexonsmith, egorzhdan Differential Revision: https://reviews.llvm.org/D127408
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).
2021-08-31[clang] Remove redundant calls to c_str() (NFC)Kazu Hirata1-1/+1
Identified with readability-redundant-string-cstr.
2021-04-06[SystemZ][z/OS][Windows] Add new OF_TextWithCRLF flag and use this flag ↵Abhina Sreeskantharajan1-1/+1
instead of OF_Text Problem: On SystemZ we need to open text files in text mode. On Windows, files opened in text mode adds a CRLF '\r\n' which may not be desirable. Solution: This patch adds two new flags - OF_CRLF which indicates that CRLF translation is used. - OF_TextWithCRLF = OF_Text | OF_CRLF indicates that the file is text and uses CRLF translation. Developers should now use either the OF_Text or OF_TextWithCRLF for text files and OF_None for binary files. If the developer doesn't want carriage returns on Windows, they should use OF_Text, if they do want carriage returns on Windows, they should use OF_TextWithCRLF. So this is the behaviour per platform with my patch: z/OS: OF_None: open in binary mode OF_Text : open in text mode OF_TextWithCRLF: open in text mode Windows: OF_None: open file with no carriage return OF_Text: open file with no carriage return OF_TextWithCRLF: open file with carriage return The Major change is in llvm/lib/Support/Windows/Path.inc to only set text mode if the OF_CRLF is set. ``` if (Flags & OF_CRLF) CrtOpenFlags |= _O_TEXT; ``` These following files are the ones that still use OF_Text which I left unchanged. I modified all these except raw_ostream.cpp in recent patches so I know these were previously in Binary mode on Windows. ./llvm/lib/Support/raw_ostream.cpp ./llvm/lib/TableGen/Main.cpp ./llvm/tools/dsymutil/DwarfLinkerForBinary.cpp ./llvm/unittests/Support/Path.cpp ./clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp ./clang/lib/Frontend/CompilerInstance.cpp ./clang/lib/Driver/Driver.cpp ./clang/lib/Driver/ToolChains/Clang.cpp Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D99426
2021-03-26[SystemZ][z/OS] Save strings for CC_PRINT env varsSean Perry1-2/+3
The contents of the string returned by getenv() is not guaranteed across calls to getenv(). The code to handle the CC_PRINT etc env vars calls getenv() and saves the results in just a char *. The string returned by getenv() needs to be copied and saved. Switching the type of the strings from char * to std::string will do this and manage the alloated memory. Differential Revision: https://reviews.llvm.org/D98554
2020-11-05[Driver] Add callback to Command executionSerge Pavlov1-0/+2
Summary: Object of type `Compilation` now can keep a callback that is called after each execution of `Command`. This must simplify adaptation of clang in custom distributions and allow facilities like collection of execution statistics. Reviewers: rsmith, rjmccall, Eugene.Zelenko Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D78899
2020-03-24[CUDA][HIP] Add -Xarch_device and -Xarch_host optionsYaxun (Sam) Liu1-3/+16
The argument after -Xarch_device will be added to the arguments for CUDA/HIP device compilation and will be removed for host compilation. The argument after -Xarch_host will be added to the arguments for CUDA/HIP host compilation and will be removed for device compilation. Differential Revision: https://reviews.llvm.org/D76520
2020-02-07Re-land "[Clang][Driver] Remove -M group options ..." and "[Clang] Avoid ↵Alexandre Ganea1-2/+11
crashing when generating crash diagnostics when '#pragma clang __debug ..." This re-lands commits f41ec709d9d388dc43469e6ac7f51b6313f7e4af (https://reviews.llvm.org/D74076) and commit 5fedc2b410853a6aef05e8edf19ebfc4e071e28f (https://reviews.llvm.org/D74070) The previous build break was caused by '#pragma clang __debug llvm_unreachable' used in a non-assert build. Move it to a separate test in crash-report-with-asserts.c.
2020-02-06Revert "[Clang][Driver] Remove -M group options ..." and "[Clang] Avoid ↵Jordan Rupprecht1-11/+2
crashing when generating crash diagnostics when '#pragma clang __debug ..." This reverts commits f41ec709d9d388dc43469e6ac7f51b6313f7e4af and 5fedc2b410853a6aef05e8edf19ebfc4e071e28f. On some buildbots, Clang :: Driver/crash-report.c is broken with: ``` Command Output (stderr): -- /home/buildslave/ps4-buildslave1/clang-with-thin-lto-ubuntu/llvm-project/clang/test/Driver/crash-report.c:48:11: error: CHECK: expected string not found in input // CHECK: Preprocessed source(s) and associated run script(s) are located at: ^ <stdin>:1:1: note: scanning from here /home/buildslave/ps4-buildslave1/clang-with-thin-lto-ubuntu/llvm-project/clang/test/Driver/crash-report.c:50:1: error: unknown type name 'BAZ' ``` Example: http://lab.llvm.org:8011/builders/clang-with-thin-lto-ubuntu/builds/21321/steps/test-stage1-compiler/logs/stdio
2020-02-06[Clang][Driver] Remove -M group options before generating crash diagnosticsAlexandre Ganea1-2/+11
Previously, when using '-MF file.d' on the command line, 'file.d' would not be deleted after a compiler crash. The code path in Compilation::initCompilationForDiagnostics() that was modifying 'TranslatedArgs' had no effect, because 'TCArgs' was already created after the crash. This was covered by clang/test/Driver/output-file-cleanup.c, the test was succeeding by fluke because Driver::generateCompilationDiagnostics() would fail to launch the subsequent clang -E (see D74070 for a fix for this). So the test was only covering Driver.cpp, C.CleanupFileMap(). After this patch, both cleanup and removal of -MF are exercised. Differential Revision: https://reviews.llvm.org/D74076
2020-01-21[PATCH] Reland [Clang] Un-break scan-build after integrated-cc1 changeAlexandre Ganea1-1/+1
The issue was reported by @xazax.hun here: https://reviews.llvm.org/D69825#1827826 "This patch (D69825) breaks scan-build-py which parses the output of "-###" to get -cc1 command. There might be other tools with the same problems. Could we either remove (in-process) from CC1Command::Print or add a line break? Having the last line as a valid invocation is valuable and there might be tools relying on that." Differential Revision: https://reviews.llvm.org/D72982
2019-08-05Rename F_{None,Text,Append} to OF_{None,Text,Append}. NFCFangrui Song1-1/+1
F_{None,Text,Append} are kept for compatibility since r334221. llvm-svn: 367800
2019-07-15Use unique_ptr instead of manual delete in one place. No behavior change.Nico Weber1-7/+5
llvm-svn: 366084
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-10-12Fix MSVC 2015 ambiguous symbol warning introduced by rL344337. NFCI.Simon Pilgrim1-1/+1
llvm-svn: 344352
2018-05-31[Driver] Clean up tmp files when deleting Compilation objectsDavid Stenberg1-0/+12
Summary: In rL327851 the createUniqueFile() and createTemporaryFile() variants that do not return the file descriptors were changed to create empty files, rather than only check if the paths are free. This change was done in order to make the functions race-free. That change led to clang-tidy (and possibly other tools) leaving behind temporary assembly files, of the form placeholder-*, when using a target that does not support the internal assembler. The temporary files are created when building the Compilation object in stripPositionalArgs(), as a part of creating the compilation database for the arguments after the double-dash. The files are created by Driver::GetNamedOutputPath(). Fix this issue by cleaning out temporary files at the deletion of Compilation objects. This fixes https://bugs.llvm.org/show_bug.cgi?id=37091. Reviewers: klimek, sepavloff, arphaman, aaron.ballman, john.brawn, mehdi_amini, sammccall, bkramer, alexfh, JDevlieghere Reviewed By: aaron.ballman, JDevlieghere Subscribers: erichkeane, lebedev.ri, Ka-Ka, cfe-commits Differential Revision: https://reviews.llvm.org/D45686 llvm-svn: 333637
2018-05-08[HIP] Add hip offload kindYaxun Liu1-4/+4
There are quite differences in HIP action builder and action job creation, which justifies to define a separate offload kind. Differential Revision: https://reviews.llvm.org/D46471 llvm-svn: 331811
2018-03-20[Driver] Fix some Clang-tidy modernize and Include What You Use warnings; ↵Eugene Zelenko1-20/+26
other minor fixes (NFC). llvm-svn: 328044
2017-11-10[Driver] Make clang/cc conforms to UNIX standardSteven Wu1-6/+41
Summary: This is basically reverting r261774 with a tweak for clang-cl. UNIX standard states: When c99 encounters a compilation error that causes an object file not to be created, it shall write a diagnostic to standard error and continue to compile other source code operands, but it shall not perform the link phase and it shall return a non-zero exit status The same goes for c89 or cc. And they are all alias or shims pointing to clang on Darwin. The original commit was intended for CUDA so the error message doesn't get emit twice for both host and device. It seems that the clang driver has been changed to model the CUDA dependency differently. Now the driver behaves the same without this commit. rdar://problem/32223263 Reviewers: thakis, dexonsmith, tra Reviewed By: tra Subscribers: jlebar, cfe-commits Differential Revision: https://reviews.llvm.org/D39502 llvm-svn: 317860
2017-10-09Testing commit access.Hamza Sood1-1/+1
llvm-svn: 315231
2017-10-04[OpenMP] Fix passing of -m arguments correctlyJonas Hahnfeld1-2/+8
The recent fix in D38258 was wrong: getAuxTriple() only returns non-null values for the CUDA toolchain. That is why the now added test for PPC and X86 failed. Differential Revision: https://reviews.llvm.org/D38372 llvm-svn: 314902
2017-09-27[OpenMP] Fix translation of target argsJonas Hahnfeld1-4/+6
ToolChain::TranslateArgs() returns nullptr if no changes are performed. This would currently mean that OpenMPArgs are lost. Patch fixes this by falling back to simply using OpenMPArgs in that case. Differential Revision: https://reviews.llvm.org/D38259 llvm-svn: 314330
2017-09-27[OpenMP] Fix memory leak when translating argumentsJonas Hahnfeld1-2/+8
Parsing the argument after -Xopenmp-target allocates memory that needs to be freed. Associate it with the final DerivedArgList after we know which one will be used. Differential Revision: https://reviews.llvm.org/D38257 llvm-svn: 314328
2017-09-13Update users of llvm::sys::ExecuteAndWait etc.Alexander Kornienko1-15/+4
Summary: Clang part of https://reviews.llvm.org/D37563 Reviewers: bkramer Subscribers: vsk, cfe-commits Differential Revision: https://reviews.llvm.org/D37564 llvm-svn: 313156
2017-08-07Non-functional change. Fix previous patch D34784.Gheorghe-Teodor Bercea1-4/+8
llvm-svn: 310282
2017-08-07[OpenMP] Add flag for specifying the target device architecture for OpenMP ↵Gheorghe-Teodor Bercea1-1/+6
device offloading Summary: OpenMP has the ability to offload target regions to devices which may have different architectures. A new -fopenmp-target-arch flag is introduced to specify the device architecture. In this patch I use the new flag to specify the compute capability of the underlying NVIDIA architecture for the OpenMP offloading CUDA tool chain. Only a host-offloading test is provided since full device offloading capability will only be available when [[ https://reviews.llvm.org/D29654 | D29654 ]] lands. Reviewers: hfinkel, Hahnfeld, carlo.bertolli, caomhin, ABataev Reviewed By: hfinkel Subscribers: guansong, cfe-commits Tags: #openmp Differential Revision: https://reviews.llvm.org/D34784 llvm-svn: 310263
2017-06-30[Driver] Actually report errors during parsing instead of stopping when ↵Benjamin Kramer1-2/+3
there's an error somewhere. This is a more principled version of r303756. That change was both very brittle about the state of the Diags object going into the driver and also broke tooling in funny ways. In particular it prevented tools from capturing diagnostics properly and made the compilation database logic fail to provide arguments to the tool, falling back to scanning directories for JSON files. llvm-svn: 306822
2016-10-27[Driver][OpenMP] Add logic for offloading-specific argument translation.Samuel Antao1-4/+5
Summary: This patch includes support for argument translation that is specific of a given offloading kind. Additionally, it implements the translation for OpenMP device kinds in the gcc tool chain. With this patch, it is possible to compile a functional OpenMP application with offloading capabilities with no separate compilation. Reviewers: echristo, tra, jlebar, rsmith, ABataev, hfinkel Subscribers: whchung, mehdi_amini, cfe-commits, Hahnfeld, andreybokhanko, arpith-jacob, carlo.bertolli, caomhin Differential Revision: https://reviews.llvm.org/D21848 llvm-svn: 285320
2016-10-07Turn ArchName/BoundArch in Driver from raw pointer to StringRef (NFC)Mehdi Amini1-6/+4
llvm-svn: 283605
2016-06-28[Driver] Add method to redirect output of Compilation.Nikolay Haustov1-0/+5
Summary: Currently output of child process, however in my use case, it needs to be captured and presented to the user. Add Redirect method to Compilation and use existing infrastructure for redirecting output of commands. Reviewers: tstellarAMD Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D21224 llvm-svn: 273997
2016-06-13[CUDA][OpenMP] Create generic offload toolchainsSamuel Antao1-3/+6
Summary: This patch introduces the concept of offloading tool chain and offloading kind. Each tool chain may have associated an offloading kind that marks it as used in a given programming model that requires offloading. It also adds the logic to iterate on the tool chains based on the kind. Currently, only CUDA is supported, but in general a programming model (an offloading kind) may have associated multiple tool chains that require supporting offloading. This patch does not add tests - its goal is to keep the existing functionality. This patch is the first of a series of three that attempts to make the current support of CUDA more generic and easier to extend to other programming models, namely OpenMP. It tries to capture the suggestions/improvements/concerns on the initial proposal in http://lists.llvm.org/pipermail/cfe-dev/2016-February/047547.html. It only tackles the more consensual part of the proposal, i.e.does not address the problem of intermediate files bundling yet. Reviewers: ABataev, jlebar, echristo, hfinkel, tra Subscribers: guansong, Hahnfeld, andreybokhanko, tcramer, mkuron, cfe-commits, arpith-jacob, carlo.bertolli, caomhin Differential Revision: http://reviews.llvm.org/D18170 llvm-svn: 272571
2016-02-24Bail on compilation as soon as a job fails.Justin Lebar1-30/+8
Summary: (Re-land of r260448, which was reverted in r260522 due to a test failure in Driver/output-file-cleanup.c that only showed up in fresh builds.) Previously we attempted to be smart; if one job failed, we'd run all jobs that didn't depend on the failing job. Problem is, this doesn't work well for e.g. CUDA compilation without -save-temps. In this case, the device-side and host-side Assemble actions (which actually are responsible for preprocess, compile, backend, and assemble, since we're not saving temps) are necessarily distinct. So our clever heuristic doesn't help us, and we repeat every error message once for host and once for each device arch. The main effect of this change, other than fixing CUDA, is that if you pass multiple cc files to one instance of clang and you get a compile error, we'll stop when the first cc1 job fails. Reviewers: echristo Subscribers: cfe-commits, jhen, echristo, tra, rafael Differential Revision: http://reviews.llvm.org/D17217 llvm-svn: 261774
2016-02-23Rename Action::begin() to Action::input_begin().Nico Weber1-2/+2
Also introduce inputs() that reutnrs an llvm::iterator_range. Iterating over A->inputs() is much less mysterious than iterating over *A. No intended behavior change. llvm-svn: 261674
2016-02-11Revert "Bail on compilation as soon as a job fails."Rafael Espindola1-8/+30
This reverts commit r260448. It was causing Driver/output-file-cleanup.c to fail. llvm-svn: 260522
2016-02-10Bail on compilation as soon as a job fails.Justin Lebar1-30/+8
Previously we attempted to be smart; if one job failed, we'd run all jobs that didn't depend on the failing job. Problem is, this doesn't work well for e.g. CUDA compilation without -save-temps. In this case, the device-side and host-side Assemble actions (which actually are responsible for preprocess, compile, backend, and assemble, since we're not saving temps) are necessarily distinct. So our clever heuristic doesn't help us, and we repeat every error message once for host and once for each device arch. The main effect of this change, other than fixing CUDA, is that if you pass multiple cc files to one instance of clang and you get a compile error, we'll stop when the first cc1 job fails. Reviewers: tra, echristo Subscribers: jhen, cfe-commits Differential Revision: http://reviews.llvm.org/D16514 llvm-svn: 260448
2016-01-11Move ownership of Action objects into Compilation.Justin Lebar1-6/+2
Summary: This makes constructing Action graphs which are DAGs much simpler. It also just simplifies in general the ownership semantics of Actions. Depends on D15910. Reviewers: echristo Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D15911 llvm-svn: 257407