Skip to content

Commit 8df20d7

Browse files
committed
[ClangImporter] For ClangImporter::getOrCreatePCH() don't verify/update the PCH if it is explicit
If the PCH is explicit use it directly; do the verify+update only for when we create an 'implicit' PCH via the -pch-output-dir option.
1 parent 7e7a630 commit 8df20d7

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

include/swift/ClangImporter/ClangImporter.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,12 @@ class ClangImporter final : public ClangModuleLoader {
308308

309309
Optional<std::string>
310310
getOrCreatePCH(const ClangImporterOptions &ImporterOptions,
311-
const std::string &SwiftPCHHash);
311+
StringRef SwiftPCHHash);
312312
Optional<std::string>
313+
/// \param isExplicit true if the PCH filename was passed directly
314+
/// with -import-objc-header option.
313315
getPCHFilename(const ClangImporterOptions &ImporterOptions,
314-
const std::string &SwiftPCHHash);
316+
StringRef SwiftPCHHash, bool &isExplicit);
315317
};
316318

317319
ImportDecl *createImportDecl(ASTContext &Ctx, DeclContext *DC, ClangNode ClangN,

lib/ClangImporter/ClangImporter.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -771,11 +771,13 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) {
771771

772772
Optional<std::string>
773773
ClangImporter::getPCHFilename(const ClangImporterOptions &ImporterOptions,
774-
const std::string &SwiftPCHHash) {
774+
StringRef SwiftPCHHash, bool &isExplicit) {
775775
if (llvm::sys::path::extension(ImporterOptions.BridgingHeader)
776776
.endswith(PCH_EXTENSION)) {
777+
isExplicit = true;
777778
return ImporterOptions.BridgingHeader;
778779
}
780+
isExplicit = false;
779781

780782
const auto &BridgingHeader = ImporterOptions.BridgingHeader;
781783
const auto &PCHOutputDir = ImporterOptions.PrecompiledHeaderOutputDir;
@@ -798,12 +800,14 @@ ClangImporter::getPCHFilename(const ClangImporterOptions &ImporterOptions,
798800

799801
Optional<std::string>
800802
ClangImporter::getOrCreatePCH(const ClangImporterOptions &ImporterOptions,
801-
const std::string &SwiftPCHHash) {
802-
auto PCHFilename = getPCHFilename(ImporterOptions, SwiftPCHHash);
803+
StringRef SwiftPCHHash) {
804+
bool isExplicit;
805+
auto PCHFilename = getPCHFilename(ImporterOptions, SwiftPCHHash,
806+
isExplicit);
803807
if (!PCHFilename.hasValue()) {
804808
return None;
805809
}
806-
if (!canReadPCH(PCHFilename.getValue())) {
810+
if (!isExplicit && !canReadPCH(PCHFilename.getValue())) {
807811
SmallString<256> Message;
808812
llvm::raw_svector_ostream OS(Message);
809813
auto Diags = new clang::TextDiagnosticPrinter {

0 commit comments

Comments
 (0)