Skip to content

Commit 5883345

Browse files
authored
[ClangImporter] Include -Xcc options in the PCH hash (#27482)
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
1 parent e2e114f commit 5883345

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
@@ -103,7 +103,8 @@ class ClangImporterOptions {
103103
using llvm::hash_combine;
104104

105105
auto Code = hash_value(ModuleCachePath);
106-
// ExtraArgs ignored - already considered in Clang's module hashing.
106+
Code = hash_combine(Code, llvm::hash_combine_range(ExtraArgs.begin(),
107+
ExtraArgs.end()));
107108
Code = hash_combine(Code, OverrideResourceDir);
108109
Code = hash_combine(Code, TargetCPU);
109110
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)