Commit Graph

70 Commits

Author SHA1 Message Date
Hans Wennborg 2fe010473d Re-commit r344234 "clang-cl: Add /showFilenames option (PR31957)"
The test was failing on e.g. PPC which can't target Windows. Fix by
requiring X86 target in the test. Also, make sure the output goes to a
temporary directory, since CWD may not be writable.

llvm-svn: 344462
2018-10-13 19:13:14 +00:00
Simon Pilgrim 0e50d4c47b Consistently make llvm::opt::ArgStringList usage explicit to try and appease MSVC 2015 buildbots. NFCI.
llvm-svn: 344398
2018-10-12 18:55:36 +00:00
Sean Fertile 518be95072 Revert "clang-cl: Add /showFilenames option (PR31957)"
This reverts https://reviews.llvm.org/rL344234 which is causing failures on
several bots due to invalid llvm.linker.options.

llvm-svn: 344276
2018-10-11 18:40:35 +00:00
Hans Wennborg fe4bfe80ff clang-cl: Add /showFilenames option (PR31957)
Add a /showFilenames option for users who want clang to echo the
currently compiled filename. MSVC does this echoing by default, and it's
useful for showing progress in build systems that doesn't otherwise
provide any progress report, such as MSBuild.

Differential Revision: https://reviews.llvm.org/D52773

llvm-svn: 344234
2018-10-11 10:04:15 +00:00
Zachary Turner 4ca9432def Fix crash in clang.
This happened during a recent refactor.  toStringRefArray() returns
a vector<StringRef>, which was being implicitly converted to an
ArrayRef<StringRef>, and then the vector was immediately being
destroyed, so the ArrayRef<> was losing its backing storage.
Fix this by making sure the vector gets permanent storage.

llvm-svn: 336219
2018-07-03 18:12:39 +00:00
Zachary Turner 08426e1f9f Refactor ExecuteAndWait to take StringRefs.
This simplifies some code which had StringRefs to begin with, and
makes other code more complicated which had const char* to begin
with.

In the end, I think this makes for a more idiomatic and platform
agnostic API.  Not all platforms launch process with null terminated
c-string arrays for the environment pointer and argv, but the api
was designed that way because it allowed easy pass-through for
posix-based platforms.  There's a little additional overhead now
since on posix based platforms we'll be takign StringRefs which
were constructed from null terminated strings and then copying
them to null terminate them again, but from a readability and
usability standpoint of the API user, I think this API signature
is strictly better.

llvm-svn: 334518
2018-06-12 17:43:52 +00:00
Adrian Prantl 9fc8faf9e6 Remove \brief commands from doxygen comments.
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-05-09 01:00:01 +00:00
Eugene Zelenko 5e4511cfc7 [Driver] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
llvm-svn: 328044
2018-03-20 21:08:59 +00:00
Erich Keane 6c4835978a Revert 320391: Certain targets are failing, pulling back to diagnose.
llvm-svn: 320398
2017-12-11 18:14:51 +00:00
Erich Keane bb322555af For Linux/gnu compatibility, preinclude <stdc-predef.h> if the file is available
As reported in llvm bugzilla 32377.
Here’s a patch to add preinclude of stdc-predef.h.

The gcc documentation says “On GNU/Linux, <stdc-predef.h> is pre-included.” See https://gcc.gnu.org/gcc-4.8/porting_to.html;

The preinclude is inhibited with –ffreestanding.

Basically I fixed the failing test cases by adding –ffreestanding which inhibits this behavior.

I fixed all the failing tests, including some in extra/test, there's a separate patch for that which is linked here

Note: this is a recommit after a test failure took down the original (r318669)

Patch By: mibintc
Differential Revision: https://reviews.llvm.org/D34158

llvm-svn: 320391
2017-12-11 17:36:42 +00:00
Erich Keane 523edb0a3a Revert r318669/318694
Broke some libclang tests, so reverting for now.

llvm-svn: 318698
2017-11-20 21:46:29 +00:00
Erich Keane 5c086c7626 For Linux/gnu compatibility, preinclude <stdc-predef.h> if the file is available
As reported in llvm bugzilla 32377.
Here’s a patch to add preinclude of stdc-predef.h.

The gcc documentation says “On GNU/Linux, <stdc-predef.h> is pre-included.” 
See https://gcc.gnu.org/gcc-4.8/porting_to.html;

The preinclude is inhibited with –ffreestanding.

Basically I fixed the failing test cases by adding –ffreestanding which inhibits
this behavior.

I fixed all the failing tests, including some in extra/test, there's a separate
patch for that which is linked here

Patch By: mibintc

Differential Revision: https://reviews.llvm.org/D34158

llvm-svn: 318669
2017-11-20 17:57:42 +00:00
Richard Smith daae9528b7 Revert r316193.
This patch breaks users using -fno-canonical-prefixes, for whom resolving
symlinks is not acceptable.

llvm-svn: 316195
2017-10-20 00:25:07 +00:00
Peter Wu 90161dad75 Try to shorten system header paths when using -MD depfiles
GCC tries to shorten system headers in depfiles using its real path
(resolving components like ".." and following symlinks). Mimic this
feature to ensure that the Ninja build tool detects the correct
dependencies when a symlink changes directory levels, see
https://github.com/ninja-build/ninja/issues/1330

An option to disable this feature is added in case "these changed header
paths may conflict with some compilation environments", see
https://gcc.gnu.org/ml/gcc-patches/2012-09/msg00287.html

Note that the original feature request for GCC
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52974) also included paths
preprocessed output (-E) and diagnostics. That is not implemented now
since I am not sure if it breaks something else.

Differential Revision: https://reviews.llvm.org/D37954

llvm-svn: 316193
2017-10-19 23:53:27 +00:00
Alexander Kornienko 1e53195c2a Attempt to fix MSVC build.
llvm-svn: 313162
2017-09-13 17:45:51 +00:00
Alexander Kornienko 9707aa74d6 Update users of llvm::sys::ExecuteAndWait etc.
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-09-13 17:03:58 +00:00
Aaron Ballman 6c60ed5a45 The -coverage-file flag was removed in r280306, and this piece was missed; NFC.
llvm-svn: 301796
2017-05-01 13:05:04 +00:00
Zachary Turner a0f96be9b1 [clang-cl] Fix cross-compilation with MSVC 2017.
clang-cl works best when the user runs vcvarsall to set up
an environment before running, but even this is not enough
on VC 2017 when cross compiling (e.g. using an x64 toolchain
to target x86, or vice versa).

The reason is that although clang-cl itself will have a
valid environment, it will shell out to other tools (such
as link.exe) which may not.  Generally we solve this through
adding the appropriate linker flags, but this is not enough
in VC 2017.

The cross-linker and the regular linker both link against
some common DLLs, but these DLLs live in the binary directory
of the native linker.  When setting up a cross-compilation
environment through vcvarsall, it will add *both* directories
to %PATH%, so that when cl shells out to any of the associated
tools, those tools will be able to find all of the dependencies
that it links against.  If you don't do this, link.exe will
fail to run because the loader won't be able to find all of
the required DLLs that it links against.

To solve this we teach the driver how to spawn a process with
an explicitly specified environment.  Then we modify the
PATH before shelling out to subtools and run with the modified
PATH.

Patch by Hamza Sood
Differential Revision: https://reviews.llvm.org/D30991

llvm-svn: 298098
2017-03-17 16:24:34 +00:00
Bruno Cardoso Lopes 7aff2bb3d2 [CrashReproducer] Collect PCH included via -include-pch
Collect the necessary input PCH files.

Do not try to validate the AST before copying it out because if the
crash is in this path, we won't be able to collect it. Instead only
check if it's a file containg an AST.

rdar://problem/27913709

llvm-svn: 289460
2016-12-12 19:28:25 +00:00
Bruno Cardoso Lopes 1c10872150 [CrashReproducer] Provide a clean dir path for -fmodules-cache-path
The most common workflow with module reproducers involves deleting the
module cache before running the script. This happens because leftovers
from the crash are present in the cache and could trigger unrelated and
confusing errors, misleading from the initial reproduction intent.
Change this to point to a clean path but leave the leftovers untouched.

rdar://problem/28655070

llvm-svn: 289176
2016-12-09 03:11:48 +00:00
Bruno Cardoso Lopes e3a0aef2cf [CrashReproducer] Rewrite relative include paths
When -fmodules is on, the reproducer invocation currently leave paths
for include-like flags as is. If the path is relative, the reproducer
doesn't know how to access that file during reproduction time because
the VFS cannot reason about relative paths.

Expand relative paths to absolute ones when creating the reproducer
command line. This allows, for example, the reproducer to work for
crashes while building clang with modules; this wasn't possible before
because building clang requires using relative inc dir from within the
build directory.

rdar://problem/28655070

llvm-svn: 289174
2016-12-09 02:22:47 +00:00
Malcolm Parsons f76f6507c2 Fix Clang-tidy readability-redundant-string-cstr warnings
Reviewers: aaron.ballman, mehdi_amini, dblaikie

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D26206

llvm-svn: 285799
2016-11-02 10:39:27 +00:00
Mehdi Amini 5bf825b764 Use StringRef in Command::printArg() instead of raw pointer (NFC)
llvm-svn: 283645
2016-10-08 01:38:43 +00:00
Mehdi Amini 9670f847b8 [NFC] Header cleanup
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
2016-07-18 19:02:11 +00:00
Bruno Cardoso Lopes b810b02b85 [CrashReproducer] Pass -I, -F and -resource-dir to the reproducer script when using modules/vfs
The reproducer should use -I/-F/-resource-dir in the same way as the
original command. The VFS already collects the right headers but without
these flags the reproducer will fail to do the right thing.

llvm-svn: 265343
2016-04-04 20:26:57 +00:00
Bruno Cardoso Lopes f854b042e7 [CrashReproducer] Add -fmodule-cache-path to reproducer script
The cc1 invocation in the reproducer script should contain a valid path in
-fmodule-cache-path; for that reuse "<name>.cache/module" dir we already
use to dump the vfs and modules.

llvm-svn: 265162
2016-04-01 17:39:08 +00:00
Nico Weber 2ca4be97de clang-cl: Implement initial limited support for precompiled headers.
In the gcc precompiled header model, one explicitly runs clang with `-x
c++-header` on a .h file to produce a gch file, and then includes the header
with `-include foo.h` and if a .gch file exists for that header it gets used.
This is documented at
http://clang.llvm.org/docs/UsersManual.html#precompiled-headers

cl.exe's model is fairly different, and controlled by the two flags /Yc and
/Yu. A pch file is generated as a side effect of a regular compilation when
/Ycheader.h is passed. While the compilation is running, the compiler keeps
track of #include lines in the main translation unit and writes everything up
to an `#include "header.h"` line into a pch file. Conversely, /Yuheader.h tells
the compiler to skip all code in the main TU up to and including `#include
"header.h"` and instead load header.pch. (It's also possible to use /Yc and /Yu
without an argument, in that case a `#pragma hrdstop` takes the role of
controlling the point where pch ends and real code begins.)

This patch implements limited support for this in that it requires the pch
header to be passed as a /FI force include flag – with this restriction,
it can be implemented almost completely in the driver with fairly small amounts
of code. For /Yu, this is trivial, and for /Yc a separate pch action is added
that runs before the actual compilation. After r261774, the first failing
command makes a compilation stop – this means if the pch fails to build the
main compilation won't run, which is what we want. However, in /fallback builds
we need to run the main compilation even if the pch build fails so that the
main compilation's fallback can run. To achieve this, add a ForceSuccessCommand
that pretends that the pch build always succeeded in /fallback builds (the main
compilation will then fail to open the pch and run the fallback cl.exe
invocation).

If /Yc /Yu are used in a setup that clang-cl doesn't implement yet, clang-cl
will now emit a "not implemented yet; flag ignored" warning that can be
disabled using -Wno-clang-cl-pch.

Since clang-cl doesn't yet serialize some important things (most notably
`pragma comment(lib, ...)`, this feature is disabled by default and only
enabled by an internal driver flag. Once it's more stable, this internal flag
will disappear.

(The default stdafx.h setup passes stdafx.h as explicit argument to /Yc but not
as /FI – instead every single TU has to `#include <stdafx.h>` as first thing it
does. Implementing support for this should be possible with the approach in
this patch with minimal frontend changes by passing a --stop-at / --start-at
flag from the driver to the frontend. This is left for a follow-up. I don't
think we ever want to support `#pragma hdrstop`, and supporting it with this
approach isn't easy: This approach relies on the driver knowing the pch
filename in advance, and `#pragma hdrstop(out.pch)` can set the output
filename, so the driver can't know about it in advance.)

clang-cl now also honors /Fp and puts pch files in the same spot that cl.exe
would put them, but the pch file format is of course incompatible. This has
ramifications on /fallback, so /Yc /Yu aren't passed through to cl.exe in
/fallback builds.

http://reviews.llvm.org/D17695

llvm-svn: 262420
2016-03-01 23:16:44 +00:00
Justin Bogner e03437c756 Driver: Strip -header-include-file and -diagnostic-log-file from crash repro scripts
These two arguments tend to refer to a local path that won't exist
when we try to reproduce a bug. Strip them.

llvm-svn: 244179
2015-08-05 23:49:44 +00:00
Justin Bogner d3371d8703 Driver: Determine file names for crash reports more reliably
Guessing which file name to replace based on the -main-file-name
argument to -cc1 is flawed. Instead, keep track of which arguments are
inputs to each command.

llvm-svn: 242504
2015-07-17 03:35:54 +00:00
Reid Kleckner e2d03448ba [clang-cl] Use the Windows response file tokenizer
We were still using the Unix response file tokenizer for all driver
modes. This was difficult to get right in the beginning because there is
a circular dependency. The Driver class also can't officially determine
its mode until it can see all possible --driver-mode= flags, and those
flags could come from the response file.

Now we use the Windows parsing algorithm if the program name looks like
clang-cl, or if the --driver-mode=cl flag is present on the main command
line.

Fixes PR23709.

Reviewers: hans

Differential Revision: http://reviews.llvm.org/D11229

llvm-svn: 242346
2015-07-15 22:42:37 +00:00
Justin Bogner ed9cbe015c Driver: Include the driver arguments in crash reports
Similarly to r231989, the driver arguments can be quite helpful in
diagnosing a crash.

llvm-svn: 241786
2015-07-09 06:58:31 +00:00
Justin Bogner 0cd9248d9e Driver: Remove the Job class. NFC
We had a strange relationship here where we made a list of Jobs
inherit from a single Job, but there weren't actually any places where
this arbitrary nesting was used or needed.

Simplify all of this by removing Job entirely and updating all of the
users to either work with a JobList or a single Command.

llvm-svn: 241310
2015-07-02 22:52:08 +00:00
Justin Bogner 94817612e2 Driver: Don't use reserved names. NFC
llvm-svn: 241309
2015-07-02 22:52:04 +00:00
Justin Bogner 0cb14759fc Driver: Keep -isysroot flags in crash scripts if we're dumping a VFS
For crashes with a VFS (ie, with modules), the -isysroot flag is often
necessary to reproduce the crash. This is especially true if some
modules need to be rebuilt, since without the sysroot they'll try to
read headers that are outside of the VFS.

I find it likely that we should keep some of the other -i flags in
this case as well, but I haven't seen that come up in practice yet so
it seems better to be conservative.

llvm-svn: 231997
2015-03-12 00:52:56 +00:00
Benjamin Kramer f989042f18 Prefer SmallVector::append/insert over push_back loops. Clang edition.
Same functionality, but hoists the vector growth out of the loop.

llvm-svn: 229508
2015-02-17 16:48:30 +00:00
Justin Bogner 33bdbc66d3 Driver: Quote the command in crash reproduction scripts.
This fixes crash report generation when filenames have spaces. It also
removes an awkward workaround that quoted *some* arguments when
generating crash reports.

llvm-svn: 220307
2014-10-21 18:03:08 +00:00
Justin Bogner 256451561c Driver: Move crash report command mangling into Command::Print
This pushes the logic for generating a crash reproduction script
entirely into Command::Print, instead of Command doing half of the
work and then relying on textual substitution for the rest. This makes
this logic much easier to read and will simplify fixing a couple of
issues in this area.

llvm-svn: 220305
2014-10-21 17:24:44 +00:00
Justin Bogner aab9792b6c Driver: Use pointee_iterator rather than iterating over unique_ptrs
There's probably never a good reason to iterate over unique_ptrs. This
lets us use range-for and say Job.foo instead of (*it)->foo in a few
places.

llvm-svn: 218938
2014-10-03 01:04:53 +00:00
Reid Kleckner 0290c9ca5c Teach Clang how to use response files when calling other tools
Patch by Rafael Auler!

This patch addresses PR15171 and teaches Clang how to call other tools
with response files, when the command line exceeds system limits. This
is a problem for Windows systems, whose maximum command-line length is
32kb.

I introduce the concept of "response file support" for each Tool object.
A given Tool may have full support for response files (e.g. MSVC's
link.exe) or only support file names inside response files, but no flags
(e.g. Apple's ld64, as commented in PR15171), or no support at all (the
default case). Therefore, if you implement a toolchain in the clang
driver and you want clang to be able to use response files in your
tools, you must override a method (getReponseFileSupport()) to tell so.

I designed it to support different kinds of tools and
internationalisation needs:

- VS response files ( UTF-16 )
- GNU tools ( uses system's current code page, windows' legacy intl.
  support, with escaped backslashes. On unix, fallback to UTF-8 )
- Clang itself ( UTF-16 on windows, UTF-8 on unix )
- ld64 response files ( only a limited file list, UTF-8 on unix )

With this design, I was able to test input file names with spaces and
international characters for Windows. When the linker input is large
enough, it creates a response file with the correct encoding. On a Mac,
to test ld64, I temporarily changed Clang's behavior to always use
response files regardless of the command size limit (avoiding using huge
command line inputs). I tested clang with the LLVM test suite (compiling
benchmarks) and it did fine.

Test Plan: A LIT test that tests proper response files support. This is
tricky, since, for Unix systems, we need a 2MB response file, otherwise
Clang will simply use regular arguments instead of a response file. To
do this, my LIT test generate the file on the fly by cloning many -DTEST
parameters until we have a 2MB file. I found out that processing 2MB of
arguments is pretty slow, it takes 1 minute using my notebook in a debug
build, or 10s in a Release build. Therefore, I also added "REQUIRES:
long_tests", so it will only run when the user wants to run long tests.

In the full discussion in
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130408/171463.html,
Rafael Espindola discusses a proper way to test
llvm::sys::argumentsFitWithinSystemLimits(), and, there, Chandler
suggests to use 10 times the current system limit (20MB resp file), so
we guarantee that the system will always use response file, even if a
new linux comes up that can handle a few more bytes of arguments.
However, by testing with a 20MB resp file, the test takes long 8 minutes
just to perform a silly check to see if the driver will use a response
file. I found it to be unreasonable. Thus, I discarded this approach and
uses a 2MB response file, which should be enough.

Reviewers: asl, rafael, silvas

Reviewed By: silvas

Subscribers: silvas, rnk, thakis, cfe-commits

Differential Revision: http://reviews.llvm.org/D4897

llvm-svn: 217792
2014-09-15 17:45:39 +00:00
David Blaikie c11bf80265 unique_ptrify JobList::Jobs
llvm-svn: 217168
2014-09-04 16:04:28 +00:00
Reid Kleckner 4f1fc35b13 Add back the leading space when printing commands with -###
This was an unintentional behavior change from r214924.

llvm-svn: 215044
2014-08-07 00:05:00 +00:00
Reid Kleckner 822434da9f Make crash diagnostics on Windows the tiniest bit more useful
This escapes any backslashes in the executable path and fixes an issue
with a trailing quote when the main file name had to be quoted during
printing.

It's impossible to test this without putting backslashes or quotes into
the executable path, so I didn't add automated tests.

The crash diagnostics are still only useful if you're using bash on
Windows, though.  This should probably be writing a batch file instead.

llvm-svn: 214924
2014-08-05 20:49:12 +00:00
Justin Bogner 61c0e43ef6 Driver: Skip the -ivfsoverlay argument in driver crash diags
llvm-svn: 211474
2014-06-22 20:35:10 +00:00
Craig Topper 92fc2dfa6f [C++11] Use 'nullptr'. Driver edition.
llvm-svn: 209069
2014-05-17 16:56:41 +00:00
Justin Bogner f893a6551b Driver: Skip the -fmodules-cache-path argument in driver crash diags
The modules cache path shouldn't be included in crash reports, as it's
a system (or run) specific directory.

llvm-svn: 206922
2014-04-22 21:30:17 +00:00
Hans Wennborg 897a69b33e clang-cl /fallback: turn the note into a warning
llvm-svn: 201626
2014-02-19 02:10:19 +00:00
Hans Wennborg c5afd06a0d clang-cl /fallback: emit a note when falling back
This makes it a lot easier to see what's going on from the output.

llvm-svn: 201604
2014-02-18 21:42:51 +00:00
Hans Wennborg 87cfa71071 clang-cl: implement /fallback mode
When this flag is enabled, clang-cl falls back to cl.exe if it
cannot compile the code itself for some reason.

The idea is to use this to help build projects that almost compile
with clang-cl, except for some files that can then be built with
the fallback mechanism.

Differential Revision: http://llvm-reviews.chandlerc.com/D1711

llvm-svn: 191034
2013-09-19 20:32:16 +00:00
Hans Wennborg e693e8432e Add comment about exporting clang::driver::ArgStringList,
as suggested by Jordan on IRC. Also, use the unqualified name
in Job.cpp.

And while we're here, refer to StringRef with the unqualified
name, because we have a using directive for that too.

llvm-svn: 190909
2013-09-18 00:41:15 +00:00
Hans Wennborg 0daa1225c6 Revert r190902 and r190906
The first one broke the build, and the latter one made it worse.

llvm-svn: 190907
2013-09-18 00:21:51 +00:00