aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/CompilerInstance.cpp
AgeCommit message (Collapse)AuthorFilesLines
2016-03-01clang-cl: Implement initial limited support for precompiled headers.Nico Weber1-4/+32
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-02-19[modules] Flatten -fmodule-name= and -fmodule-implementation-of= into a singleRichard Smith1-8/+2
option. Previously these options could both be used to specify that you were compiling the implementation file of a module, with a different set of minor bugs in each case. This change removes -fmodule-implementation-of, and instead tracks a flag to determine whether we're currently building a module. -fmodule-name now behaves the same way that -fmodule-implementation-of previously did. llvm-svn: 261372
2016-02-13Reduce the number of implicit StringRef->std::string conversions by ↵Benjamin Kramer1-1/+1
threading StringRef through more APIs. No functionality change intended. llvm-svn: 260815
2015-12-16Update for llvm API change.Rafael Espindola1-1/+0
llvm-svn: 255838
2015-11-16[Frontend] Rangify for loop. NFC.Vedant Kumar1-2/+2
llvm-svn: 253178
2015-11-05[modules] If we're given a module file, via -fmodule-file=, for a module, butRichard Smith1-4/+24
we can't load that file due to a configuration mismatch, and implicit module building is disabled, and the user turns off the error-by-default warning for that situation, then fall back to textual inclusion for the module rather than giving an error if any of its headers are included. llvm-svn: 252114
2015-11-03Introduce module file extensions to piggy-back data onto module files.Douglas Gregor1-5/+9
Introduce the notion of a module file extension, which introduces additional information into a module file at the time it is built that can then be queried when the module file is read. Module file extensions are identified by a block name (which must be unique to the extension) and can write any bitstream records into their own extension block within the module file. When a module file is loaded, any extension blocks are matched up with module file extension readers, that are per-module-file and are given access to the input bitstream. Note that module file extensions can only be introduced by programmatic clients that have access to the CompilerInvocation. There is only one such extension at the moment, which is used for testing the module file extension harness. As a future direction, one could imagine allowing the plugin mechanism to introduce new module file extensions. llvm-svn: 251955
2015-10-16[modules] Allow the error when explicitly loading an incompatible module fileRichard Smith1-5/+14
via -fmodule-file= to be turned off; in that case, just include the relevant files textually. This allows module files to be unconditionally passed to all compile actions via CXXFLAGS, and to be ignored for rules that specify custom incompatible flags. llvm-svn: 250577
2015-10-05Use llvm::errc instead of std::errc.Rafael Espindola1-1/+1
llvm-svn: 249302
2015-10-03Replace double negation of !FileID.isInvalid() with FileID.isValid().Yaron Keren1-3/+3
+couple more of double-negated !SourceLocation.isInvalid() unfixed in r249228. llvm-svn: 249235
2015-09-22[CUDA] Allow parsing of host and device code simultaneously.Artem Belevich1-5/+11
* adds -aux-triple option to specify target triple * propagates aux target info to AST context and Preprocessor * pulls in target specific preprocessor macros. * pulls in target-specific builtins from aux target. * sets appropriate host or device attribute on builtins. Differential Revision: http://reviews.llvm.org/D12917 llvm-svn: 248299
2015-09-17createOutputFile should set Error to something if it returns null.Douglas Katzman1-1/+3
This is not portably unit-testable because the only visible effect is a change from one random message string to another. llvm-svn: 247900
2015-08-18Initialize the AST consumer as soon as we have both an ASTConsumer and anRichard Smith1-8/+15
ASTContext. Fixes some cases where we could previously initialize the AST consumer more than once. llvm-svn: 245346
2015-08-17[modules] When explicitly building a module file, don't include timestamps inRichard Smith1-0/+1
the produced pcm file for stable file creation across distributed build systems. llvm-svn: 245199
2015-08-15[modules] Stop dropping 'module.timestamp' files into the current directoryRichard Smith1-3/+6
when building with implicit modules disabled. llvm-svn: 245136
2015-08-13Add sanitizer blacklists to the rules generated with -M/-MM/-MD/-MMD.Ivan Krasin1-3/+5
Summary: Clang sanitizers, such as AddressSanitizer, ThreadSanitizer, MemorySanitizer, Control Flow Integrity and others, use blacklists to specify which types / functions should not be instrumented to avoid false positives or suppress known failures. This change adds the blacklist filenames to the list of dependencies of the rules, generated with -M/-MM/-MD/-MMD. This lets CMake/Ninja recognize that certain C/C++/ObjC files need to be recompiled (if a blacklist is updated). Reviewers: pcc Subscribers: rsmith, honggyu.kim, pcc, cfe-commits Differential Revision: http://reviews.llvm.org/D11968 llvm-svn: 244867
2015-08-11Fix some tabs.Richard Smith1-4/+3
llvm-svn: 244537
2015-08-09[modules] Remove now-dead code for lazy loading of files specified by ↵Richard Smith1-17/+3
-fmodule-file=. llvm-svn: 244417
2015-08-09[modules] PR22534: Load files specified by -fmodule-file= eagerly. In ↵Richard Smith1-69/+30
particular, this avoids the need to re-parse module map files when using such a module. llvm-svn: 244416
2015-08-09Unrevert r244412 (reverted in r244414), and delete the bogus line left behindRichard Smith1-1/+3
in the unit test that was checking a file the test no longer creates. llvm-svn: 244415
2015-08-09Revert "[modules] Don't leak -M flags for dependency file generation into ↵Justin Bogner1-3/+1
the module" This was failing tests on a bunch of bots: http://lab.llvm.org:8011/builders/clang-hexagon-elf/builds/29919/steps/check-all http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/29627/steps/check-all http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_check/9959/ http://lab.llvm.org:8080/green/job/clang-stage2-configure-Rlto_check/5591/ This reverts r244412 llvm-svn: 244414
2015-08-09[modules] Don't leak -M flags for dependency file generation into the moduleRichard Smith1-1/+3
build process when we implicitly build a module. Previously, we'd create the specified .d file once for each implicitly-built module and then finally overwrite it with the correct contents after the requested build completes. (This fails if you use stdout as a dependency file, which is what the provided testcase does, and is how I discovered this brokenness.) llvm-svn: 244412
2015-08-09[modules] Attach dependency listeners to the module manager once when it'sRichard Smith1-9/+7
created, rather than creating and attaching a new listener each time we load a module file (yes, the old ones were kept around too!). No functionality change intended, but a bit more sanity. llvm-svn: 244411
2015-07-21[modules] Produce an error if -cc1 wants to implicitly build a module and noRichard Smith1-8/+7
module cache has been provided, rather than creating one in the current directory. llvm-svn: 242819
2015-07-17Make the clang module container format selectable from the command line.Adrian Prantl1-8/+8
- introduces a new cc1 option -fmodule-format=[raw,obj] with 'raw' being the default - supports arbitrary module container formats that libclang is agnostic to - adds the format to the module hash to avoid collisions - splits the old PCHContainerOperations into PCHContainerWriter and a PCHContainerReader. Thanks to Richard Smith for reviewing this patch! llvm-svn: 242499
2015-07-14Extend -ftime-report to give more information about time spent reading ↵Richard Smith1-2/+19
module files. llvm-svn: 242094
2015-07-06Replace some const std::string & with llvm::StringRef or std::stringYaron Keren1-3/+3
and std::move to avoid implicit std::string construction. Patch by Eugene Kosov. llvm-svn: 241433
2015-07-03Revert r241330. It compiled with Visual C++ 2013 and gcc 4.9.1 (mingw) but ↵Yaron Keren1-3/+3
now fails the bots. llvm-svn: 241335
2015-07-03Replace some const std::string & with llvm::StringRef or std::stringYaron Keren1-3/+3
and std::move to avoid implicit std::string construction. Patch by Eugene Kosov. llvm-svn: 241330
2015-07-03Revert r241319, investigating.Yaron Keren1-3/+3
llvm-svn: 241321
2015-07-03Replace some const std::string & with llvm::StringRef or std::stringYaron Keren1-3/+3
and std::move to avoid implicit std::string construction. Part 1/2. Patch by Eugene Kosov. llvm-svn: 241319
2015-06-20Introduce a PCHContainerOperations interface (NFC).Adrian Prantl1-25/+31
A PCHContainerOperations abstract interface provides operations for creating and unwrapping containers for serialized ASTs (precompiled headers and clang modules). The default implementation is RawPCHContainerOperations, which uses a flat file for the output. The main application for this interface will be an ObjectFilePCHContainerOperations implementation that uses LLVM to wrap the module in an ELF/Mach-O/COFF container to store debug info alongside the AST. rdar://problem/20091852 llvm-svn: 240225
2015-05-29Replace push_back(Constructor(foo)) with emplace_back(foo) for non-trivial typesBenjamin Kramer1-3/+2
If the type isn't trivially moveable emplace can skip a potentially expensive move. It also saves a couple of characters. Call sites were found with the ASTMatcher + some semi-automated cleanup. memberCallExpr( argumentCountIs(1), callee(methodDecl(hasName("push_back"))), on(hasType(recordDecl(has(namedDecl(hasName("emplace_back")))))), hasArgument(0, bindTemporaryExpr( hasType(recordDecl(hasNonTrivialDestructor())), has(constructExpr()))), unless(isInTemplateInstantiation())) No functional change intended. llvm-svn: 238601
2015-05-18[modules] Move implicit creation of ImportDecls for #includes transformed ↵Richard Smith1-19/+0
into module imports from the frontend into Sema where it belongs. llvm-svn: 237555
2015-05-16[modules] Retain the name as written for umbrella headers and directories, ↵Richard Smith1-3/+5
rather than converting to an absolute path. No observable change expected, but this allows us to correctly compute the module for an umbrella header, which later changes will require. llvm-svn: 237508
2015-05-15[modules] Add local submodule visibility support for declarations.Richard Smith1-0/+5
With this change, enabling -fmodules-local-submodule-visibility results in name visibility rules being applied to submodules of the current module in addition to imported modules (that is, names no longer "leak" between submodules of the same top-level module). This also makes it much safer to textually include a non-modular library into a module: each submodule that textually includes that library will get its own "copy" of that library, and so the library becomes visible no matter which including submodule you import. llvm-svn: 237473
2015-05-01[modules] Start moving the module visibility information off the Module itself.Richard Smith1-6/+4
It has no place there; it's not a property of the Module, and it makes restoring the visibility set when we leave a submodule more difficult. llvm-svn: 236300
2015-04-29[modules] Stop trying to fake up a linear MacroDirective history.Richard Smith1-63/+35
Modules builds fundamentally have a non-linear macro history. In the interest of better source fidelity, represent the macro definition information faithfully: we have a linear macro directive history within each module, and at any point we have a unique "latest" local macro directive and a collection of visible imported directives. This also removes the attendent complexity of attempting to create a correct MacroDirective history (which we got wrong in the general case). No functionality change intended. llvm-svn: 236176
2015-04-14Use raw_pwrite_stream in clang.Rafael Espindola1-13/+17
This is a small improvement to -emit-pth and allows llvm to start requiring it. llvm-svn: 234897
2015-04-10[Frontend] Close open file handles before renaming output filesReid Kleckner1-10/+12
The placement of the 'delete' call that was removed in the unique_ptr migration in r234597 was not an accident. The raw_ostream has to be destroyed before you do the rename on Windows, otherwise you get ERROR_ACCESS_DENIED. We can still use unique_ptr, we just need to do a manual reset(). Also, range-for-loop-ify this code. llvm-svn: 234612
2015-04-10Return std::unique_ptr to avoid a release and recreate.Rafael Espindola1-4/+4
llvm-svn: 234598
2015-04-10Use a std::unique_ptr to make it easier to see who owns the stream.Rafael Espindola1-10/+11
llvm-svn: 234597
2015-03-28[Modules] Don't compute a modules cache path if we're not using modules!Chandler Carruth1-1/+2
Notably, this prevents us from doing *tons* of work to compute the modules hash, including trying to read a darwin specific plist file off of the system. There is a lot that needs cleaning up below this layer too. llvm-svn: 233462
2015-03-24[Modules] Stop creating timestamps for the modules cache and trying toChandler Carruth1-3/+4
prune it when we have disabled implicit module generation and thus are not using any cached modules. Also update a test of explicitly generated modules to pass this CC1 flag correctly. This fixes an issue where Clang was dropping files into the source tree while running its tests. llvm-svn: 233117
2015-03-18Remove many superfluous SmallString::str() calls.Yaron Keren1-5/+4
Now that SmallString is a first-class citizen, most SmallString::str() calls are not required. This patch removes a whole bunch of them, yet there are lots more. There are two use cases where str() is really needed: 1) To use one of StringRef member functions which is not available in SmallString. 2) To convert to std::string, as StringRef implicitly converts while SmallString do not. We may wish to change this, but it may introduce ambiguity. llvm-svn: 232622
2015-03-18Make module files passed to a module build via -fmodule-file= available toRichard Smith1-0/+13
consumers of that module. Previously, such a file would only be available if the module happened to actually import something from that module. llvm-svn: 232583
2015-02-28Give better diagnostics when -fmodule-file= finds a bad file: if the file isRichard Smith1-3/+13
found indirectly, explain how we got there, and distinguish between 'file not found' and 'file found but invalid'. llvm-svn: 230839
2015-02-25[modules] Even if we already have a definition of a class, loading in anotherRichard Smith1-1/+4
one can give us more lookup results (due to implicit special members). Be sure to complete the redecl chain for every kind of DeclContext before performing a lookup into it, rather than only doing so for NamespaceDecls. llvm-svn: 230558
2015-02-25[modules] Fix a bug that would result in a build with P paths through a moduleRichard Smith1-0/+3
graph with M modules to take O(P) time, not just O(M) time, when using explicit module builds. llvm-svn: 230412
2015-02-20Add -fno-implicit-modules.Manuel Klimek1-0/+6
If this flag is set, we error out when a module build is required. This is useful in environments where all required modules are passed via -fmodule-file. llvm-svn: 230006