aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Serialization/GeneratePCH.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-07-15[clang][modules] Serialize `CodeGenOptions` (#146422)Jan Svoboda1-2/+4
Some `LangOptions` duplicate their `CodeGenOptions` counterparts. My understanding is that this was done solely because some infrastructure (like preprocessor initialization, serialization, module compatibility checks, etc.) were only possible/convenient for `LangOptions`. This PR implements the missing support for `CodeGenOptions`, which makes it possible to remove some duplicate `LangOptions` fields and simplify the logic. Motivated by https://github.com/llvm/llvm-project/pull/146342.
2025-03-21[clang] NFCI: Mutate `HeaderSearchOptions` earlier (#130823)Jan Svoboda1-7/+0
2025-03-14[clang][modules] Introduce new `ModuleCache` interface (#131193)Jan Svoboda1-4/+4
This PR adds new `ModuleCache` interface to Clang's implicitly-built modules machinery. The main motivation for this change is to create a second implementation that uses a more efficient kind of `llvm::AdvisoryLock` during dependency scanning. In addition to the lock abstraction, the `ModuleCache` interface also manages the existing `InMemoryModuleCache` instance. I found that compared to keeping these separate/independent, the code is a bit simpler now, since these are two tightly coupled concepts. I can envision a more efficient implementation of the `InMemoryModuleCache` for the single-process case too, which will be much easier to implement with the current setup. This is not intended to be a functional change.
2025-01-16[clang][Serialization] Stop including Frontend headers from Serialization ↵Jorge Gorbe Moya1-1/+1
(NFC) (#123140) The Frontend library depends on Serialization. This is an explicit dependency encoded in the CMake target. However, Serialization currently has an implicit dependency on Frontend, as it includes one of its headers. This is not reflected in the CMake build rules, but Bazel is stricter so, in order to avoid a dependency cycle, it hackily declares the Frontend headers as source files for Serialization. Fortunately, the only Frontend header used by Serialization is clang/Frontend/FrontendDiagnostic.h, which is a legacy header that just includes clang/Basic/DiagnosticFrontend since d076608d58d1ec55016eb747a995511e3a3f72aa, back in 2018. This commit changes Serialization to use the underlying header from Basic instead. Both Serialization and Frontend depend on Basic, so this breaks the dependency cycle.
2025-01-03[clang] Allow generating module interfaces with parsing errors (#121485)Alejandro Álvarez Ayllón1-2/+3
Fixes a regression introduced in commit da00c60dae0040185dc45039c4397f6e746548e9 This functionality was originally added in commit 5834996fefc937d6211dc8c8a5b200068753391a Co-authored-by: Tomasz Kaminski <tomasz.kaminski@sonarsource.com>
2024-11-11[clang][deps] Only write preprocessor info into PCMs (#115239)Jan Svoboda1-5/+14
This patch builds on top of https://github.com/llvm/llvm-project/pull/115237 and https://github.com/llvm/llvm-project/pull/115235, only passing the `Preprocessor` object to `ASTWriter`. This reduces the size of scanning PCM files by 1/3 and speeds up scans by 16%.
2024-11-11[clang][serialization] Enable `ASTWriter` to work with `Preprocessor` only ↵Jan Svoboda1-1/+1
(#115237) This PR builds on top of https://github.com/llvm/llvm-project/pull/115235 and makes it possible to call `ASTWriter::WriteAST()` with `Preprocessor` only instead of full `Sema` object. So far, there are no clients that leverage the new capability - that will come in a follow-up commit.
2024-04-30[NFC] [C++20] [Modules] Use new class CXX20ModulesGenerator to genera… ↵Chuanqi Xu1-11/+14
(#90570) …te module file for C++20 modules instead of PCHGenerator Previously we're re-using PCHGenerator to generate the module file for C++20 modules. But this is slighty more or less odd. This patch tries to use a new class 'CXX20ModulesGenerator' to generate the module file for C++20 modules.
2024-04-30[C++20] [Modules] Don't skip pragma diagnostic mappingsChuanqi Xu1-1/+0
Close https://github.com/llvm/llvm-project/issues/75057 Previously, I thought the diagnostic mappings is not meaningful with modules incorrectly. And this problem get revealed by another change recently. So this patch tried to rever the previous "optimization" partially.
2024-04-30Revert "[C++20] [Modules] Don't skip pragma diagnostic mappings"Chuanqi Xu1-8/+12
and "[NFC] [C++20] [Modules] Use new class CXX20ModulesGenerator to generate module file for C++20 modules instead of PCHGenerator" This reverts commit fb21343473e33e9a886b42d2fe95d1cec1cd0030. and commit 18268ac0f48d93c2bcddb69732761971669c09ab. It looks like there are some problems about linking the compiler
2024-04-30[C++20] [Modules] Don't skip pragma diagnostic mappingsChuanqi Xu1-1/+0
Close https://github.com/llvm/llvm-project/issues/75057 Previously, I thought the diagnostic mappings is not meaningful with modules incorrectly. And this problem get revealed by another change recently. So this patch tried to rever the previous "optimization" partially.
2024-04-30[NFC] [C++20] [Modules] Use new class CXX20ModulesGenerator to generate ↵Chuanqi Xu1-11/+8
module file for C++20 modules instead of PCHGenerator Previously we're re-using PCHGenerator to generate the module file for C++20 modules. But this is slighty more or less odd. This patch tries to use a new class 'CXX20ModulesGenerator' to generate the module file for C++20 modules.
2024-04-16[unused-includes][Serialization] Remove unused includes. NFC. (#88790)Volodymyr Sapsai1-1/+0
2024-04-03[NFC] Check the nullness of pointer before dereference it in the assertionChuanqi Xu1-1/+1
This was part of https://github.com/llvm/llvm-project/pull/85050. It is suggested to split the unrelated change as much as possible. So here is the patch.
2024-04-03[NFC] [C++20] [Modules] [Reduced BMI] Make sure the size of reduced BMI is ↵Chuanqi Xu1-3/+16
not large than full BMI Before this patch, the size of the reduced BMI may be large than the full BMI when the source codes is pretty small. This violates the design principles. The root cause is an oversight that we skipped something in full BMI but forgot to make it in reduced BMI.
2024-03-13[NFC] [C++20] [Modules] Refactor ReducedBMIGeneratorChuanqi Xu1-15/+27
Changes: - Don't lookup the emitting module from HeaderSearch. We will use the module from the ASTContext directly. - Remove some useless arguments. Let's addback in the future if required.
2024-03-08[C++20] [Modules] Introduce reduced BMI (#75894)Chuanqi Xu1-2/+35
Close https://github.com/llvm/llvm-project/issues/71034 See https://discourse.llvm.org/t/rfc-c-20-modules-introduce-thin-bmi-and-decls-hash/74755 This patch introduces reduced BMI, which doesn't contain the definitions of functions and variables if its definitions won't contribute to the ABI. Testing is a big part of the patch. We want to make sure the reduced BMI contains the same behavior with the existing and relatively stable fatBMI. This is pretty helpful for further reduction. The user interfaces part it left to following patches to ease the reviewing.
2023-10-06Revert "Revert "Fixes and closes #53952. Setting the ASTHasCompilerErrors ↵Aaron Ballman1-6/+2
member variable correctly based on the PP diagnostics. (#68127)"" This reverts commit a6acf3fd49a20c570a390af2a3c84e10b9545b68 and relands a50e63b38b931d945f97eac882278068221eca17. The original revert was done by mistake.
2023-10-05Revert "Fixes and closes #53952. Setting the ASTHasCompilerErrors member ↵Kazu Hirata1-2/+6
variable correctly based on the PP diagnostics. (#68127)" This reverts commit a50e63b38b931d945f97eac882278068221eca17. With clang-14.0.6 as the host compiler, I'm getting: ld.lld: error: undefined symbol: clang::ASTWriter::WriteAST(clang::Sema&, llvm::StringRef, clang::Module*, llvm::StringRef, bool, bool) >>> referenced by ASTUnit.cpp >>> ASTUnit.cpp.o:(clang::ASTUnit::serialize(llvm::raw_ostream&)) in archive lib/libclangFrontend.a
2023-10-05Fixes and closes #53952. Setting the ASTHasCompilerErrors member variable ↵Rajkumar Ananthu1-6/+2
correctly based on the PP diagnostics. (#68127) The issue #53952 is reported indicating clang is giving a crashing pch file, when hasErrors is been passed incorrectly to WriteAST method. To fix the issue, the parameter has been removed and instead we're relying on the results of `hasUncompilableErrorOccured()` instead of letting the caller override it. Fixes https://github.com/llvm/llvm-project/issues/53952
2023-08-17[clang][modules] Avoid storing command-line macro definitions into ↵Jan Svoboda1-2/+2
implicitly built PCM files With implicit modules, it's impossible to load a PCM file that was built using different command-line macro definitions. This is guaranteed by the fact that they contribute to the context hash. This means that we don't need to store those macros into PCM files for validation purposes. This patch avoids serializing them in those circumstances, since there's no other use for command-line macro definitions (besides "-module-file-info"). For a typical Apple project, this speeds up the dependency scan by 5.6% and shrinks the cache with scanning PCMs by 26%. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D158136
2022-08-05[Serialization] Remove `ORIGINAL_PCH_DIR` recordArgyrios Kyrtzidis1-4/+3
Use of `ORIGINAL_PCH_DIR` record has been superseeded by making PCH/PCM files with relocatable paths at write time. Removing this record is useful for producing an output-path-independent PCH file and enable sharing of the same PCH file even when it was intended for a different output path. Differential Revision: https://reviews.llvm.org/D131124
2022-07-29[ASTWriter] Provide capability to output a PCM/PCH file that does not write ↵Argyrios Kyrtzidis1-3/+4
out information about its output path This is useful to enable sharing of the same PCH file even when it's intended for a different output path. The only information this option disables writing is for `ORIGINAL_PCH_DIR` record which is treated as optional and (when present) used as fallback for resolving input file paths relative to it. Differential Revision: https://reviews.llvm.org/D130710
2021-10-12[clang][modules] NFC: Propagate import `SourceLocation` into ↵Jan Svoboda1-1/+2
`HeaderSearch::lookupModule` This patch propagates the import `SourceLocation` into `HeaderSearch::lookupModule`. This enables remarks on search path usage (implemented in D102923) to point to the source code that initiated header search. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D111557
2020-03-31[pch] Honour -fallow-pch-with-compiler-errors for overall compilation statusBen Langmuir1-0/+5
Previously we would emit a PCH with errors, but fail the overall compilation. If run using the driver, that would result in removing the just-produced PCH. Instead, we should have the compilation result match whether we were able to emit the PCH. Differential Revision: https://reviews.llvm.org/D77159 rdar://61110294
2019-07-03[Bitcode] Move Bitstream to a separate libraryFrancis Visoiu Mistrih1-1/+1
This moves Bitcode/Bitstream*, Bitcode/BitCodes.h to Bitstream/. This is needed to avoid a circular dependency when using the bitstream code for parsing optimization remarks. Since Bitcode uses Core for the IR part: libLLVMRemarks -> Bitcode -> Core and Core uses libLLVMRemarks to generate remarks (see IR/RemarkStreamer.cpp): Core -> libLLVMRemarks we need to separate the Bitstream and Bitcode part. For clang-doc, it seems that it doesn't need the whole bitcode layer, so I updated the CMake to only use the bitstream part. Differential Revision: https://reviews.llvm.org/D63899 llvm-svn: 365091
2019-03-12Modules: Add LangOptions::CacheGeneratedPCHDuncan P. N. Exon Smith1-3/+6
Add an option to cache the generated PCH in the ModuleCache when emitting it. This protects clients that build PCHs and read them in the same process, allowing them to avoid race conditions between parallel jobs the same way that Clang's implicit module build system does. rdar://problem/48740787 llvm-svn: 355950
2019-03-09Modules: Rename MemoryBufferCache to InMemoryModuleCacheDuncan P. N. Exon Smith1-3/+3
Change MemoryBufferCache to InMemoryModuleCache, moving it from Basic to Serialization. Another patch will start using it to manage module build more explicitly, but this is split out because it's mostly mechanical. Because of the move to Serialization we can no longer abuse the Preprocessor to forward it to the ASTReader. Besides the rename and file move, that means Preprocessor::Preprocessor has one fewer parameter and ASTReader::ASTReader has one more. llvm-svn: 355777
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
2017-03-21Apply clang-tidy's performance-unnecessary-value-param to parts of clang.Benjamin Kramer1-3/+3
No functionality change intended. llvm-svn: 298443
2017-03-20Reapply "Modules: Cache PCMs in memory and avoid a use-after-free"Duncan P. N. Exon Smith1-1/+2
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-2/+1
This reverts commit r298165, as it broke the ARM builds. llvm-svn: 298185
2017-03-17Modules: Cache PCMs in memory and avoid a use-after-freeDuncan P. N. Exon Smith1-1/+2
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/+1
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-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-08-26C++ Modules TS: add frontend support for building pcm files from moduleRichard Smith1-2/+5
interface files. At the moment, all declarations (and no macros) are exported, and 'export' declarations are not supported yet. llvm-svn: 279794
2016-08-25Refactor to remove the assumption that we know the name of the module we're ↵Richard Smith1-6/+13
emitting at the point when we create a PCHGenerator (with the C++ modules TS, we find that out part way through parsing the input). llvm-svn: 279766
2016-07-18[NFC] Header cleanupMehdi Amini1-4/+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-13[PCH/preamble] Make sure that if the preamble/PCH was serialized with errors ↵Argyrios Kyrtzidis1-1/+4
that we set diagnostic engine state appropriately. Otherwise there can be a crash with CFG analysis warnings doing work on invalid AST. Fixes crash of rdar://26224134 llvm-svn: 275313
2015-11-03Introduce module file extensions to piggy-back data onto module files.Douglas Gregor1-5/+7
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-20Roll-back r250822.Angel Garcia Gomez1-1/+2
Summary: It breaks the build for the ASTMatchers Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D13893 llvm-svn: 250827
2015-10-20Apply modernize-use-default to clang.Angel Garcia Gomez1-2/+1
Summary: Replace empty bodies of default constructors and destructors with '= default'. Reviewers: bkramer, klimek Subscribers: klimek, alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13890 llvm-svn: 250822
2015-09-22Module Debugging: Use the clang module signature as the module's dwo_idAdrian Prantl1-1/+2
when building a module. Clang already records the module signature when building a skeleton CU to reference a clang module. Matching the id in the skeleton with the one in the module allows a DWARF consumer to verify that they found the correct version of the module without them needing to know about the clang module format. llvm-svn: 248345
2015-08-17[modules] When explicitly building a module file, don't include timestamps inRichard Smith1-2/+3
the produced pcm file for stable file creation across distributed build systems. llvm-svn: 245199
2015-06-29Remove unnecessary include.Adrian Prantl1-1/+0
llvm-svn: 240963
2015-06-20Introduce a PCHContainerOperations interface (NFC).Adrian Prantl1-22/+11
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-02-25Revert "Wrap clang module files in a Mach-O, ELF, or COFF container."Adrian Prantl1-6/+12
llvm-svn: 230454
2015-02-25Wrap clang module files in a Mach-O, ELF, or COFF container.Adrian Prantl1-12/+6
This is a necessary prerequisite for debugging with modules. The .pcm files become containers that hold the serialized AST which allows us to store debug information in the module file that can be shared by all object files that were built importing the module. This reapplies r230044 with a fixed configure+make build and updated dependencies and testcase requirements. Over the last iteration this version adds - missing target requirements for testcases that specify an x86 triple, - a missing clangCodeGen.a dependency to libClang.a in the make build. rdar://problem/19104245 llvm-svn: 230423
2015-02-24Revert "Wrap clang module files in a Mach-O, ELF, or COFF container."Adrian Prantl1-6/+12
This reverts commit r230305. Off to fix another round of missing dependencies on various platforms. llvm-svn: 230309
2015-02-24Wrap clang module files in a Mach-O, ELF, or COFF container.Adrian Prantl1-12/+6
This is a necessary prerequisite for debugging with modules. The .pcm files become containers that hold the serialized AST which allows us to store debug information in the module file that can be shared by all object files that were built importing the module. rdar://problem/19104245 This reapplies r230044 with a fixed configure+make build and updated dependencies. Take 3. llvm-svn: 230305