aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/CompilerInstance.cpp
AgeCommit message (Collapse)AuthorFilesLines
2017-06-29Teach ASTReader how to read only the Preprocessor state from an AST file, ↵Richard Smith1-2/+2
not the ASTContext state. We use this when running a preprocessor-only action on an AST file in order to avoid paying the runtime cost of loading the extra information. llvm-svn: 306760
2017-06-29[OpenMP] Add support for auxiliary triple specificationGheorghe-Teodor Bercea1-2/+3
Summary: Device offloading requires the specification of an additional flag containing the triple of the //other// architecture the code is being compiled on if such an architecture exists. If compiling for the host, the auxiliary triple flag will contain the triple describing the device and vice versa. Reviewers: arpith-jacob, sfantao, caomhin, carlo.bertolli, ABataev, Hahnfeld, jlebar, hfinkel, tstellar Reviewed By: Hahnfeld Subscribers: rengolin, cfe-commits Differential Revision: https://reviews.llvm.org/D29339 llvm-svn: 306689
2017-06-29Track the set of module maps read while building a .pcm file and reload ↵Richard Smith1-2/+5
those when preprocessing from that .pcm file. llvm-svn: 306628
2017-06-19Support non-identifier module names when preprocessing modules.Richard Smith1-2/+9
llvm-svn: 305758
2017-06-09Add -frewrite-imports flag.Richard Smith1-4/+6
If specified, when preprocessing, the contents of imported .pcm files will be included in preprocessed output. The resulting preprocessed file can then be compiled standalone without the module sources or .pcm files. llvm-svn: 305116
2017-06-09Add #pragma clang module build/endbuild pragmas for performing a module buildRichard Smith1-69/+165
as part of a compilation. This is intended for two purposes: 1) Writing self-contained test cases for modules: we can now write a single source file test that builds some number of module files on the side and imports them. 2) Debugging / test case reduction. A single-source testcase is much more amenable to reduction, compared to a VFS tarball or .pcm files. llvm-svn: 305101
2017-06-05Factor out and unify emission of "module is unavailable" diagnostics.Richard Smith1-14/+4
Inspired by post-commit review of r304190. llvm-svn: 304728
2017-06-03Added LLVM_FALLTHROUGH to address warning: this statement may fall through. NFC.Galina Kistanova1-0/+1
llvm-svn: 304645
2017-04-28Move functionality for handling module maps as inputs from the -emit-moduleRichard Smith1-9/+11
action to the general FrontendAction infrastructure. This permits applying -E, -ast-dump, -fsyntax-only, and so on to a module map compilation. (The -E form is not currently especially useful yet as there's no good way to take the output and use it to actually build a module.) In order to support this, -cc1 now accepts -x <lang>-module-map in all cases where it accepts -x <lang> for a language we can parse (not ir/ast). And for uniformity, we also accept -x <lang>-header for all such languages (we used to reject for cuda and renderscript), and -x <lang>-cpp-output for all such languages (we used to reject for c, cl, and renderscript). (None of these new alternatives are accepted by the driver yet, so no user-visible changes.) llvm-svn: 301610
2017-04-27Preprocessor: Suppress -Wnonportable-include-path for header mapsDuncan P. N. Exon Smith1-1/+2
If a file search involves a header map, suppress -Wnonportable-include-path. It's firing lots of false positives for framework authors internally, and it's not trivial to fix. Consider a framework called "Foo" with a main (installed) framework header "Foo/Foo.h". It's atypical for "Foo.h" to actually live inside a directory called "Foo" in the source repository. Instead, the build system generates a header map while building the framework. If Foo.h lives at the top-level of the source repository (common), and the git repo is called ssh://some.url/foo.git, then the header map will have something like: Foo/Foo.h -> /Users/myname/code/foo/Foo.h where "/Users/myname/code/foo" is the clone of ssh://some.url/foo.git. After #import <Foo/Foo.h>, the current implementation of -Wnonportable-include-path will falsely assume that Foo.h was found in a nonportable way, because of the name of the git clone (.../foo/Foo.h). However, that directory name was not involved in the header search at all. This commit adds an extra parameter to Preprocessor::LookupFile and HeaderSearch::LookupFile to track if the search used a header map, making it easy to suppress the warning. Longer term, once we find a way to avoid the false positive, we should turn the warning back on. rdar://problem/28863903 llvm-svn: 301592
2017-04-26Refactor frontend InputKind to prepare for treating module maps as a ↵Richard Smith1-6/+7
distinct kind of input. No functionality change intended. llvm-svn: 301442
2017-03-29[PCH] Attach instance's dependency collectors to PCH external AST sources.Graydon Hoare1-0/+10
Summary: When a PCH is included via -include-pch, clang should treat the current TU as dependent on the sourcefile that the PCH was generated from. This is currently _partly_ accomplished by InitializePreprocessor calling AddImplicitIncludePCH to synthesize an implicit #include of the sourcefile, into the preprocessor's Predefines buffer. For FrontendActions such as PreprocessOnlyAction (which is, curiously, what the driver winds up running one of in response to a plain clang -M) this is sufficient: the preprocessor cranks over its Predefines and emits a dependency reference to the initial sourcefile. For other FrontendActions (for example -emit-obj or -fsyntax-only) the Predefines buffer is reset to the suggested predefines buffer from the PCH, so the dependency edge is lost. The result is that clang emits a .d file in those cases that lacks a reference to the .h file responsible for the input (and in Swift's case, our .swiftdeps file winds up not including a reference to the source file for a PCH bridging header.) This patch fixes the problem by taking a different tack: ignoring the Predefines buffer (which seems a bit like a hack anyways) and directly attaching the CompilerInstance's DependencyCollectors (and legacy DependencyFileGenerator) to the ASTReader for the external AST. This approach is similar to the one chosen in earlier consultation with Bruno and Ben, and I think it's the least-bad solution, given several options. Reviewers: bruno, benlangmuir, doug.gregor Reviewed By: bruno, doug.gregor Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D31378 llvm-svn: 299009
2017-03-22Move setting of LangOpts based on target flags out of CompilerInstanceEric Christopher1-6/+0
and into TargetInfo::adjust so that it gets called in more places throughout the compiler (AST serialization in particular). Should fix PPC modules after removing of faltivec. llvm-svn: 298487
2017-03-21Remove the -faltivec alias option and replace it with -maltivec everywhere.Eric Christopher1-0/+6
The alias was only ever used on darwin and had some issues there, and isn't used in practice much. Also fixes a problem with -mno-altivec not turning off -maltivec. Also add a diagnostic for faltivec/fno-altivec that directs users to use maltivec options and include the altivec.h file explicitly. llvm-svn: 298449
2017-03-20Reapply "Modules: Cache PCMs in memory and avoid a use-after-free"Duncan P. N. Exon Smith1-6/+17
This reverts commit r298185, effectively reapplying r298165, after fixing the new unit tests (PR32338). The memory buffer generator doesn't null-terminate the MemoryBuffer it creates; this version of the commit informs getMemBuffer about that to avoid the assert. Original commit message follows: ---- Clang's internal build system for implicit modules uses lock files to ensure that after a process writes a PCM it will read the same one back in (without contention from other -cc1 commands). Since PCMs are read from disk repeatedly while invalidating, building, and importing, the lock is not released quickly. Furthermore, the LockFileManager is not robust in every environment. Other -cc1 commands can stall until timeout (after about eight minutes). This commit changes the lock file from being necessary for correctness to a (possibly dubious) performance hack. The remaining benefit is to reduce duplicate work in competing -cc1 commands which depend on the same module. Follow-up commits will change the internal build system to continue after a timeout, and reduce the timeout. Perhaps we should reconsider blocking at all. This also fixes a use-after-free, when one part of a compilation validates a PCM and starts using it, and another tries to swap out the PCM for something new. The PCMCache is a new type called MemoryBufferCache, which saves memory buffers based on their filename. Its ownership is shared by the CompilerInstance and ModuleManager. - The ModuleManager stores PCMs there that it loads from disk, never touching the disk if the cache is hot. - When modules fail to validate, they're removed from the cache. - When a CompilerInstance is spawned to build a new module, each already-loaded PCM is assumed to be valid, and is frozen to avoid the use-after-free. - Any newly-built module is written directly to the cache to avoid the round-trip to the filesystem, making lock files unnecessary for correctness. Original patch by Manman Ren; most testcases by Adrian Prantl! llvm-svn: 298278
2017-03-18Revert "Modules: Cache PCMs in memory and avoid a use-after-free"Renato Golin1-17/+6
This reverts commit r298165, as it broke the ARM builds. llvm-svn: 298185
2017-03-18[Modules] In case of lock timeout, fallback and build moduleBruno Cardoso Lopes1-5/+12
Duncan's r298165 introduced the PCMCache mechanism, which guarantees that locks aren't necessary anymore for correctness but only for performance, by avoiding building it twice when possible. Change the logic to avoid an error but actually build the module in case the timeout happens. Instead of an error, still emit a remark for debugging purposes. rdar://problem/30297862 llvm-svn: 298175
2017-03-17Modules: Cache PCMs in memory and avoid a use-after-freeDuncan P. N. Exon Smith1-6/+17
Clang's internal build system for implicit modules uses lock files to ensure that after a process writes a PCM it will read the same one back in (without contention from other -cc1 commands). Since PCMs are read from disk repeatedly while invalidating, building, and importing, the lock is not released quickly. Furthermore, the LockFileManager is not robust in every environment. Other -cc1 commands can stall until timeout (after about eight minutes). This commit changes the lock file from being necessary for correctness to a (possibly dubious) performance hack. The remaining benefit is to reduce duplicate work in competing -cc1 commands which depend on the same module. Follow-up commits will change the internal build system to continue after a timeout, and reduce the timeout. Perhaps we should reconsider blocking at all. This also fixes a use-after-free, when one part of a compilation validates a PCM and starts using it, and another tries to swap out the PCM for something new. The PCMCache is a new type called MemoryBufferCache, which saves memory buffers based on their filename. Its ownership is shared by the CompilerInstance and ModuleManager. - The ModuleManager stores PCMs there that it loads from disk, never touching the disk if the cache is hot. - When modules fail to validate, they're removed from the cache. - When a CompilerInstance is spawned to build a new module, each already-loaded PCM is assumed to be valid, and is frozen to avoid the use-after-free. - Any newly-built module is written directly to the cache to avoid the round-trip to the filesystem, making lock files unnecessary for correctness. Original patch by Manman Ren; most testcases by Adrian Prantl! llvm-svn: 298165
2017-03-13Modules: Use hash of PCM content for SIGNATUREDuncan P. N. Exon Smith1-1/+3
Change ASTFileSignature from a random 32-bit number to the hash of the PCM content. - Move definition ASTFileSignature to Basic/Module.h so Module and ASTSourceDescriptor can use it. - Change the signature from uint64_t to std::array<uint32_t,5>. - Stop using (saving/reading) the size and modification time of PCM files when there is a valid SIGNATURE. - Add UNHASHED_CONTROL_BLOCK, and use it to store the SIGNATURE record and other records that shouldn't affect the hash. Because implicit modules reuses the same file for multiple levels of -Werror, this includes DIAGNOSTIC_OPTIONS and DIAG_PRAGMA_MAPPINGS. This helps to solve a PCH + implicit Modules dependency issue: PCH files are handled by the external build system, whereas implicit modules are handled by internal compiler build system. This prevents invalidating a PCH when the compiler overwrites a PCM file with the same content (modulo the diagnostic differences). Design and original patch by Manman Ren! llvm-svn: 297655
2017-02-02Modules: Simplify CompilerInstance constructor, NFCDuncan P. N. Exon Smith1-4/+1
Initialize fields directly in header. Note that the ModuleManager field is an IntrusiveRefCntPtr, so there's no need for explicit initialization. llvm-svn: 293863
2017-01-06Reapply "IntrusiveRefCntPtr -> std::shared_ptr for CompilerInvocationBase ↵David Blaikie1-6/+8
and CodeCompleteConsumer" Aleksey Shlypanikov pointed out my mistake in migrating an explicit unique_ptr to auto - I was expecting the function returned a unique_ptr, but instead it returned a raw pointer - introducing a leak. Thanks Aleksey! This reapplies r291184, reverted in r291249. llvm-svn: 291270
2017-01-06Revert "IntrusiveRefCntPtr -> std::shared_ptr for CompilerInvocationBase and ↵David Blaikie1-8/+6
CodeCompleteConsumer" Caused a memory leak reported by asan. Reverting while I investigate. This reverts commit r291184. llvm-svn: 291249
2017-01-06shared_ptrify (from InclusiveRefCntPtr) HeaderSearchOptionsDavid Blaikie1-5/+3
llvm-svn: 291202
2017-01-05IntrusiveRefCntPtr -> std::shared_ptr for CompilerInvocationBase and ↵David Blaikie1-6/+8
CodeCompleteConsumer llvm-svn: 291184
2017-01-05Move Preprocessor over to std::shared_ptr rather than IntrusiveRefCntPtrDavid Blaikie1-5/+7
llvm-svn: 291166
2017-01-05Move PreprocessorOptions to std::shared_ptr from IntrusiveRefCntPtrDavid Blaikie1-2/+3
llvm-svn: 291160
2017-01-05Move FailedModulesSet over to shared_ptr from IntrusiveRefCntPtrDavid Blaikie1-1/+2
llvm-svn: 291159
2017-01-05Use shared_ptr instead of IntrusiveRefCntPtr for ModuleFileExtensionDavid Blaikie1-1/+1
The intrusiveness wasn't needed here, so this simplifies/clarifies the ownership model. llvm-svn: 291150
2016-12-22[CrashReproducer] Add support for merging -ivfsoverlayBruno Cardoso Lopes1-0/+21
Merge all VFS mapped files inside -ivfsoverlay inputs into the vfs overlay provided by the crash reproducer. This is the last missing piece to allow crash reproducers to fully work with user frameworks; when combined with headermaps, it allows clang to find additional frameworks. rdar://problem/27913709 llvm-svn: 290326
2016-12-12[CrashReproducer] Collect PCH included via -include-pchBruno Cardoso Lopes1-0/+33
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-11[CrashReproducer] Collect headermap filesBruno Cardoso Lopes1-1/+13
Include headermaps (.hmap files) in the .cache directory and add VFS entries. All headermaps are known after HeaderSearch setup, collect them right after. rdar://problem/27913709 llvm-svn: 289360
2016-12-06Revert r288626, which reverts r288449. Original commit message:Richard Smith1-4/+17
Recover better from an incompatible .pcm file being provided by -fmodule-file=. We try to include the headers of the module textually in this case, still enforcing the modules semantic rules. In order to make that work, we need to still track that we're entering and leaving the module. Also, if the module was also marked as unavailable (perhaps because it was missing a file), we shouldn't mark the module unavailable -- we don't need the module to be complete if we're going to enter it textually. llvm-svn: 288741
2016-12-04Revert "Recover better from an incompatible .pcm file being provided by ↵Daniel Jasper1-17/+4
-fmodule-file=. We try to include the headers of the module textually in this case, still enforcing the modules semantic rules. In order to make that work, we need to still track that we're entering and leaving the module. Also, if the module was also marked as unavailable (perhaps because it was missing a file), we shouldn't mark the module unavailable -- we don't need the module to be complete if we're going to enter it textually." This reverts commit r288449. I believe that this is currently faulty wrt. modules being imported inside namespaces. Adding these lines to the new test: namespace n { #include "foo.h" } Makes it break with fatal error: import of module 'M' appears within namespace 'n' However, I believe it should fail with error: redundant #include of module 'M' appears within namespace 'n' I have tracked this down to us now inserting a tok::annot_module_begin instead of a tok::annot_module_include in Preprocessor::HandleIncludeDirective() and then later in Parser::parseMisplacedModuleImport(), we hit the code path for tok::annot_module_begin, which doesn't set FromInclude of checkModuleImportContext to true (thus leading to the "wrong" diagnostic). llvm-svn: 288626
2016-12-02Recover better from an incompatible .pcm file being provided by -fmodule-file=.Richard Smith1-4/+17
We try to include the headers of the module textually in this case, still enforcing the modules semantic rules. In order to make that work, we need to still track that we're entering and leaving the module. Also, if the module was also marked as unavailable (perhaps because it was missing a file), we shouldn't mark the module unavailable -- we don't need the module to be complete if we're going to enter it textually. llvm-svn: 288449
2016-11-18Adapt to llvm NamedRegionTimer changesMatthias Braun1-5/+10
We have to specify a name and description for the timers and groups now. llvm-svn: 287371
2016-11-18[CUDA] Initialize our header search using the host triple.Justin Lebar1-2/+9
Summary: This used to work because system headers are found in a (somewhat) predictable set of locations on Linux. But this is not the case on MacOS; without this change, we don't look in the right places for our headers when doing device-side compilation on Mac. Reviewers: tra Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D26776 llvm-svn: 287286
2016-11-16[Frontend] Allow attaching an external sema source to compiler instance and ↵Benjamin Kramer1-0/+10
extra diags to TypoCorrections This can be used to append alternative typo corrections to an existing diag. include-fixer can use it to suggest includes to be added. Differential Revision: https://reviews.llvm.org/D26745 llvm-svn: 287128
2016-10-21Switch SmallSetVector to use DenseSet when it overflows its inline space.Justin Lebar1-1/+2
Summary: SetVector already used DenseSet, but SmallSetVector used std::set. This leads to surprising performance differences. Moreover, it means that the set of key types accepted by SetVector and SmallSetVector are quite different! In order to make this change, we had to convert some callsites that used SmallSetVector<std::string, N> to use SmallSetVector<CachedHashString, N> instead. Reviewers: timshen Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D25648 llvm-svn: 284887
2016-09-27Adapt to LLVM EnableStatistics() change.Matthias Braun1-1/+1
llvm-svn: 282533
2016-09-26CC1: Add -save-stats optionMatthias Braun1-4/+19
This option behaves in a similar spirit as -save-temps and writes internal llvm statistics in json format to a file. Differential Revision: https://reviews.llvm.org/D24820 llvm-svn: 282426
2016-08-26C++ Modules TS: add frontend support for building pcm files from moduleRichard Smith1-1/+1
interface files. At the moment, all declarations (and no macros) are exported, and 'export' declarations are not supported yet. llvm-svn: 279794
2016-08-18Module: add -fprebuilt-module-path to support loading prebuilt modules.Manman Ren1-9/+60
In this mode, there is no need to load any module map and the programmer can simply use "@import" syntax to load the module directly from a prebuilt module path. When loading from prebuilt module path, we don't support rebuilding of the module files and we ignore compatible configuration mismatches. rdar://27290316 Differential Revision: http://reviews.llvm.org/D23125 llvm-svn: 279096
2016-08-09[OpenCL][AMDGPU] Add support for -cl-denorms-are-zeroYaxun Liu1-0/+3
Adjust target features for amdgcn target when -cl-denorms-are-zero is set. Denormal support is controlled by feature strings fp32-denormals fp64-denormals in amdgcn target. If -cl-denorms-are-zero is not set and the command line does not set fp32/64-denormals feature string, +fp32-denormals +fp64-denormals will be on for GPU's supporting them. A new virtual function virtual void TargetInfo::adjustTargetOptions(const CodeGenOptions &CGOpts, TargetOptions &TargetOpts) const is introduced to allow adjusting target option by codegen option. Differential Revision: https://reviews.llvm.org/D22815 llvm-svn: 278151
2016-07-18[NFC] Header cleanupMehdi Amini1-0/+1
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-15Frontend: Simplify ownership model for clang's output streams.Peter Collingbourne1-16/+7
This changes the CompilerInstance::createOutputFile function to return a std::unique_ptr<llvm::raw_ostream>, rather than an llvm::raw_ostream implicitly owned by the CompilerInstance. This in most cases required that I move ownership of the output stream to the relevant ASTConsumer. The motivation for this change is to allow BackendConsumer to be a client of interfaces such as D20268 which take ownership of the output stream. Differential Revision: http://reviews.llvm.org/D21537 llvm-svn: 275507
2016-06-12Add some std::move where the value is only read otherwise.Benjamin Kramer1-2/+2
This mostly affects smart pointers. No functionality change intended. llvm-svn: 272520
2016-06-04[Modules] Improve diagnostics for LockFileManager errorsBruno Cardoso Lopes1-1/+1
Uses error message now provided by LockFileManager in LLVM r271755. rdar://problem/26529101 llvm-svn: 271758
2016-05-27Apply clang-tidy's misc-move-constructor-init throughout Clang.Benjamin Kramer1-1/+3
No functionality change intended, maybe a tiny performance improvement. llvm-svn: 270996
2016-04-29[CUDA] Copy host builtin types to NVPTXTargetInfo.Justin Lebar1-1/+2
Summary: Host and device types must match, otherwise when we pass values back and forth between the host and device, we will get the wrong result. This patch makes NVPTXTargetInfo inherit most of its type information from the host's target info. Reviewers: rsmith Subscribers: cfe-commits, jhen, tra Differential Revision: http://reviews.llvm.org/D19346 llvm-svn: 268131
2016-04-08revert SVN r265702, r265640Saleem Abdulrasool1-4/+2
Revert the two changes to thread CodeGenOptions into the TargetInfo allocation and to fix the layering violation by moving CodeGenOptions into Basic. Code Generation is arguably not particularly "basic". This addresses Richard's post-commit review comments. This change purely does the mechanical revert and will be followed up with an alternate approach to thread the desired information into TargetInfo. llvm-svn: 265806