Skip to content

Commit 878d6c2

Browse files
committed
[Module interface] Ensure that we keep #ifs for compiler workarounds.
Fixes rdar://76236364.
1 parent e6b7e5e commit 878d6c2

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

lib/AST/InlinableText.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ class IsFeatureCheck : public ASTWalker {
5555
foundFeature = true;
5656
}
5757

58+
if (auto call = dyn_cast<CallExpr>(expr)) {
59+
if (auto unresolved = dyn_cast<UnresolvedDeclRefExpr>(call->getFn())) {
60+
StringRef userFacing = unresolved->getName().getBaseName()
61+
.userFacingName();
62+
if (userFacing == "compiler" || userFacing == "_compiler_version")
63+
foundFeature = true;
64+
}
65+
}
66+
5867
return { !foundFeature, expr };
5968
}
6069
};
@@ -128,10 +137,9 @@ struct ExtractInactiveRanges : public ASTWalker {
128137
return false;
129138
}
130139

131-
// If the clause is checking for a particular feature with $, keep
132-
// the whole thing.
140+
// If the clause is checking for a particular feature with $ or a compiler
141+
// version, keep the whole thing.
133142
if (anyClauseIsFeatureCheck(icd->getClauses())) {
134-
addRange(start, end);
135143
return false;
136144
}
137145

test/ModuleInterface/if-configs.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,19 @@ public func hasClosureDefaultArgWithSinglePoundIf(_ x: () -> Void = {
109109
#endif
110110
}) {
111111
}
112+
113+
// CHECK: func hasIfCompilerCheck
114+
// CHECK: #if compiler(>=5.3)
115+
// CHECK-NEXT: return true
116+
// CHECK-NEXT: #else
117+
// CHECK-NEXT: return false
118+
// CHECK-NEXT: #endif
119+
@_alwaysEmitIntoClient
120+
public func hasIfCompilerCheck(_ x: () -> Bool = {
121+
#if compiler(>=5.3)
122+
return true
123+
#else
124+
return false
125+
#endif
126+
}) {
127+
}

0 commit comments

Comments
 (0)