Skip to content

GlobalOpt: fix linkage and mangling of generated getter functions. #5579

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 1 commit into from
Nov 1, 2016
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
6 changes: 4 additions & 2 deletions lib/SILOptimizer/IPO/GlobalOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ static SILFunction *genGetterFromInit(StoreInst *Store,
auto *varDecl = SILG->getDecl();

Mangle::Mangler getterMangler;
getterMangler.append("_T");
getterMangler.mangleGlobalGetterEntity(varDecl);
auto getterName = getterMangler.finalize();

Expand Down Expand Up @@ -231,7 +232,7 @@ static SILFunction *genGetterFromInit(StoreInst *Store,
ParameterConvention::Direct_Owned, { }, Results, None,
Store->getModule().getASTContext());
auto *GetterF = Store->getModule().getOrCreateFunction(Store->getLoc(),
getterName, SILLinkage::PrivateExternal, LoweredType,
getterName, SILLinkage::Private, LoweredType,
IsBare_t::IsBare, IsTransparent_t::IsNotTransparent,
IsFragile_t::IsFragile);
GetterF->setDebugScope(Store->getFunction()->getDebugScope());
Expand Down Expand Up @@ -470,6 +471,7 @@ static SILFunction *genGetterFromInit(SILFunction *InitF, VarDecl *varDecl) {
// Generate a getter from the global init function without side-effects.

Mangle::Mangler getterMangler;
getterMangler.append("_T");
getterMangler.mangleGlobalGetterEntity(varDecl);
auto getterName = getterMangler.finalize();

Expand All @@ -486,7 +488,7 @@ static SILFunction *genGetterFromInit(SILFunction *InitF, VarDecl *varDecl) {
ParameterConvention::Direct_Owned, { }, Results, None,
InitF->getASTContext());
auto *GetterF = InitF->getModule().getOrCreateFunction(InitF->getLocation(),
getterName, SILLinkage::PrivateExternal, LoweredType,
getterName, SILLinkage::Private, LoweredType,
IsBare_t::IsBare, IsTransparent_t::IsNotTransparent,
IsFragile_t::IsFragile);
if (InitF->hasUnqualifiedOwnership())
Expand Down
23 changes: 23 additions & 0 deletions test/SILOptimizer/globalopt_linkage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: %target-swift-frontend -O -Xllvm -sil-disable-pass=Inliner -emit-sil -primary-file %s | %FileCheck %s

// Check if GlobalOpt generates the getters with the right linkage and the right mangling

struct MyStruct {
static let StaticVar = 10
}

let Global = 27

func testit() -> Int {
return MyStruct.StaticVar + Global
}

_ = testit()

// CHECK: sil hidden @{{.*}}testit

// CHECK: // MyStruct.StaticVar.getter
// CHECK-NEXT: sil private [fragile] @_{{.*}}StaticVar

// CHECK: // Global.getter
// CHECK-NEXT: sil private [fragile] @_{{.*}}Global