Skip to content

Commit b0a3961

Browse files
authored
Merge pull request #26435 from xymus/silence-outdated-pch-error
ClangImporter: silence error on outdated PCH files
2 parents 58c05e5 + 6aa0b06 commit b0a3961

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,10 +826,15 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) {
826826
};
827827
ctx.InitBuiltinTypes(CI.getTarget());
828828

829+
auto failureCapabilities =
830+
clang::ASTReader::ARR_Missing |
831+
clang::ASTReader::ARR_OutOfDate |
832+
clang::ASTReader::ARR_VersionMismatch;
833+
829834
auto result = Reader->ReadAST(PCHFilename,
830835
clang::serialization::MK_PCH,
831836
clang::SourceLocation(),
832-
clang::ASTReader::ARR_None);
837+
failureCapabilities);
833838
switch (result) {
834839
case clang::ASTReader::Success:
835840
return true;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Dummy file to test PCH loading errors
2+
3+
int c_func(int x) {
4+
return x + 27;
5+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Check that there are no errors printed when trying to load an outdated PCH file
2+
// rdar://problem/53312911
3+
4+
// RUN: %empty-directory(%t)
5+
// RUN: cp %S/Inputs/pch-loading-error.h %t/pch-loading-error.h
6+
// RUN: %target-swift-frontend -parse-as-library -module-name=pch_loading_error -emit-sil %s -enable-objc-interop -import-objc-header %t/pch-loading-error.h -pch-output-dir %t/pch
7+
// RUN: %S/../ParseableInterface/ModuleCache/Inputs/make-old.py %t/pch/*
8+
// RUN: echo "// force newer header than pch" >> %t/pch-loading-error.h
9+
// RUN: %target-swift-frontend -parse-as-library -module-name=pch_loading_error -emit-sil %s -enable-objc-interop -import-objc-header %t/pch-loading-error.h -pch-output-dir %t/pch 2>&1 | %FileCheck %s
10+
// RUN: %S/../ParseableInterface/ModuleCache/Inputs/check-is-new.py %t/pch/*
11+
12+
// CHECK-NOT: fatal error
13+
14+
public func mytest(x: Int32) -> Int32 {
15+
return c_func(x)
16+
}

0 commit comments

Comments
 (0)