MandatoryPerformanceOptimization: don't recursive into referenced functions if they are not called

Fixes a false compiler error when referencing a function from a global with a section attribute.

rdar://154332540
This commit is contained in:
Erik Eckstein
2025-06-27 09:57:19 +02:00
parent 92fd571d07
commit 8758b557fa
3 changed files with 44 additions and 3 deletions

View File

@@ -535,7 +535,24 @@ fileprivate struct FunctionWorklist {
for inst in function.instructions {
switch inst {
case let fri as FunctionRefInst:
pushIfNotVisited(fri.referencedFunction)
// In embedded swift all reachable functions must be handled - even if they are not called,
// e.g. referenced by a global.
if context.options.enableEmbeddedSwift {
pushIfNotVisited(fri.referencedFunction)
}
case let apply as ApplySite:
if let callee = apply.referencedFunction {
pushIfNotVisited(callee)
}
case let bi as BuiltinInst:
switch bi.id {
case .Once, .OnceWithContext:
if let fri = bi.operands[1].value as? FunctionRefInst {
pushIfNotVisited(fri.referencedFunction)
}
default:
break
}
case let alloc as AllocRefInst:
if context.options.enableEmbeddedSwift {
addVTableMethods(forClassType: alloc.type, context)