Skip to content

Fixing the strong imported async frame pointer flags #40035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/IRGen/IRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1834,6 +1834,19 @@ void IRGenModule::emitSwiftAsyncExtendedFrameInfoWeakRef() {
extendedFramePointerFlagsWeakRef = new llvm::GlobalVariable(Module, Int8PtrTy, false,
llvm::GlobalValue::ExternalWeakLinkage, nullptr,
symbolName);

// The weak imported extendedFramePointerFlagsWeakRef gets optimized out
// before being added back as a strong import.
// Declarations can't be added to the used list, so we create a little
// global that can't be used from the program, but can be in the used list to
// avoid optimizations.
llvm::GlobalVariable *usage = new llvm::GlobalVariable(
Module, extendedFramePointerFlagsWeakRef->getType(), false,
llvm::GlobalValue::LinkOnceODRLinkage,
static_cast<llvm::GlobalVariable *>(extendedFramePointerFlagsWeakRef),
"_swift_async_extendedFramePointerFlagsUser");
usage->setVisibility(llvm::GlobalValue::HiddenVisibility);
addUsedGlobal(usage);
}

bool IRGenModule::isConcurrencyAvailable() {
Expand Down
8 changes: 8 additions & 0 deletions test/Concurrency/Backdeploy/weak_linking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// RUN: %FileCheck %s --check-prefix=NEW < %t/new.ir
// RUN: %target-swift-frontend %s -target x86_64-apple-macosx10.15 -module-name main -emit-ir -o %t/old.ir -disable-availability-checking
// RUN: %FileCheck %s --check-prefix=OLD < %t/old.ir
// RUN: %target-swift-frontend %s -target x86_64-apple-macosx10.15 -O -module-name main -emit-ir -o %t/optimized.ir -disable-availability-checking
// RUN: %FileCheck %s --check-prefix=OPTIMIZED < %t/optimized.ir


// REQUIRES: OS=macosx

Expand All @@ -12,6 +15,11 @@
// OLD: declare extern_weak swiftcc %swift.metadata_response @"$sScPMa"
// OLD: declare extern_weak swiftcc i8 @"$sScP8rawValues5UInt8Vvg"

// OPTIMIZED: @swift_async_extendedFramePointerFlags = extern_weak global i8*
// OPTIMIZED: @_swift_async_extendedFramePointerFlagsUser = linkonce_odr hidden global i8** @swift_async_extendedFramePointerFlags
// OPTIMIZED: @llvm.used =
// OPTIMIZED-SAME: (i8*** @_swift_async_extendedFramePointerFlagsUser to i8*)

@available(macOS 12.0, *)
public func g() async -> String { "hello" }

Expand Down