Skip to content

Commit 25a507d

Browse files
authored
[ClangImporter] Include -Xcc options in the PCH hash (#27496)
While most -Xcc options turn into options that affect the Clang module cache hash, some, like search paths, do not, and that can have a drastic effect on PCH contents. When combined with places where Xcode will modify invocations to add extra -Xcc options (see rdar://problem/23297285), this can lead to crashes where the modified-invocation PCH is used to compile source files in incremental mode, and then the original, non-precompiled bridging header is used for module merging. Let's just be conservative and include -Xcc options in the Swift-side PCH uniqueness hash. rdar://problem/33837253 (cherry picked from commit 5883345)
1 parent 5624365 commit 25a507d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

include/swift/ClangImporter/ClangImporterOptions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ class ClangImporterOptions {
107107
using llvm::hash_combine;
108108

109109
auto Code = hash_value(ModuleCachePath);
110-
// ExtraArgs ignored - already considered in Clang's module hashing.
110+
Code = hash_combine(Code, llvm::hash_combine_range(ExtraArgs.begin(),
111+
ExtraArgs.end()));
111112
Code = hash_combine(Code, OverrideResourceDir);
112113
Code = hash_combine(Code, TargetCPU);
113114
Code = hash_combine(Code, BridgingHeader);

test/ClangImporter/pch-bridging-header.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
// RUN: not %target-swift-frontend -typecheck %s -import-objc-header %S/Inputs/sdk-bridging-header.h -pch-output-dir %t/no-pch -pch-disable-validation 2>&1 | %FileCheck %s -check-prefix=NO-VALIDATION
4747
// NO-VALIDATION: PCH file {{.*}} not found
4848

49+
// Test that -Xcc options are considered in the PCH hash.
50+
// RUN: %target-swift-frontend -emit-pch -pch-output-dir %t/pch-Xcc %S/Inputs/sdk-bridging-header.h
51+
// RUN: %target-swift-frontend -emit-pch -pch-output-dir %t/pch-Xcc %S/Inputs/sdk-bridging-header.h -Xcc -Ifoo
52+
// RUN: %target-swift-frontend -emit-pch -pch-output-dir %t/pch-Xcc %S/Inputs/sdk-bridging-header.h -Xcc -Ibar
53+
// RUN: ls %t/pch-Xcc/*swift*clang*.pch | count 3
54+
4955
import Foundation
5056

5157
let not = MyPredicate.not()

0 commit comments

Comments
 (0)