mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
CrossModuleOptimization: public global variables must not be serialized if they reference private functions/closures
For example:
```
public static var privateFunctionPointer: (Int) -> (Int) = { $0 }
```
Fixes a verifier crash and/or undefined symbol error
rdar://99493254
This commit is contained in:
@@ -313,6 +313,16 @@ bool CrossModuleOptimization::canSerializeGlobal(SILGlobalVariable *global) {
|
||||
for (const SILInstruction &initInst : *global) {
|
||||
if (auto *FRI = dyn_cast<FunctionRefInst>(&initInst)) {
|
||||
SILFunction *referencedFunc = FRI->getReferencedFunction();
|
||||
|
||||
// In conservative mode we don't want to turn non-public functions into
|
||||
// public functions, because that can increase code size. E.g. if the
|
||||
// function is completely inlined afterwards.
|
||||
// Also, when emitting TBD files, we cannot introduce a new public symbol.
|
||||
if ((conservative || M.getOptions().emitTBD) &&
|
||||
!hasPublicVisibility(referencedFunc->getLinkage())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!canUseFromInline(referencedFunc))
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user