Skip to content

[4.0] IRGen: Fix linkage for shared declarations #12164

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
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
3 changes: 2 additions & 1 deletion lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,8 @@ getIRLinkage(const UniversalLinkageInfo &info, SILLinkage linkage,

case SILLinkage::Shared:
case SILLinkage::SharedExternal:
return RESULT(LinkOnceODR, Hidden, Default);
return isDefinition ? RESULT(LinkOnceODR, Hidden, Default)
: RESULT(External, Hidden, Default);

case SILLinkage::Hidden:
return RESULT(External, Hidden, Default);
Expand Down
7 changes: 7 additions & 0 deletions test/IRGen/Inputs/usr/include/NSOption.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#define CF_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type
#define NS_OPTIONS(_type, _name) CF_OPTIONS(_type, _name)

typedef NS_OPTIONS(int, SomeOptions) {
SomeOptionsFoo = 1,
SomeOptionsBar = 2,
};
16 changes: 16 additions & 0 deletions test/IRGen/objc_shared_imported_decl.sil
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %target-swift-frontend -primary-file %s -import-objc-header %S/Inputs/usr/include/NSOption.h -emit-ir | %FileCheck %s

// REQUIRES: objc_interop

import Swift

sil public @use_witness : $@convention(thin) () -> () {
%0 = witness_method $SomeOptions, #Equatable."=="!1 : <Self where Self : Equatable> (Self.Type) -> (Self, Self) -> Bool : $@convention(witness_method) <τ_0_0 where τ_0_0 : Equatable> (@in τ_0_0, @in τ_0_0, @thick τ_0_0.Type) -> Bool
%1 = tuple ()
return %1: $()
}

// We used to emit linkonce_odr llvm linkage for this declaration.
sil_witness_table shared SomeOptions : Equatable module __ObjC

// CHECK: @_T0SC11SomeOptionsVs9EquatableSoWP = external hidden global