Skip to content

Commit cec02ff

Browse files
committed
[4.0] IRGen: Fix linkage for shared declarations
They need external linkage not linkonce_odr which can only be used by defintions not declarations. This got exposed by clang imported protocol witness table declarations. They get assigned shared linkage since they are potentially not unique. rdar://26563441 (cherry picked from commit 3d34fb3)
1 parent a779fa1 commit cec02ff

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,8 @@ getIRLinkage(const UniversalLinkageInfo &info, SILLinkage linkage,
14161416

14171417
case SILLinkage::Shared:
14181418
case SILLinkage::SharedExternal:
1419-
return RESULT(LinkOnceODR, Hidden, Default);
1419+
return isDefinition ? RESULT(LinkOnceODR, Hidden, Default)
1420+
: RESULT(External, Hidden, Default);
14201421

14211422
case SILLinkage::Hidden:
14221423
return RESULT(External, Hidden, Default);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#define CF_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type
2+
#define NS_OPTIONS(_type, _name) CF_OPTIONS(_type, _name)
3+
4+
typedef NS_OPTIONS(int, SomeOptions) {
5+
SomeOptionsFoo = 1,
6+
SomeOptionsBar = 2,
7+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-swift-frontend -primary-file %s -import-objc-header %S/Inputs/usr/include/NSOption.h -emit-ir | %FileCheck %s
2+
3+
// REQUIRES: objc_interop
4+
5+
import Swift
6+
7+
sil public @use_witness : $@convention(thin) () -> () {
8+
%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
9+
%1 = tuple ()
10+
return %1: $()
11+
}
12+
13+
// We used to emit linkonce_odr llvm linkage for this declaration.
14+
sil_witness_table shared SomeOptions : Equatable module __ObjC
15+
16+
// CHECK: @_T0SC11SomeOptionsVs9EquatableSoWP = external hidden global

0 commit comments

Comments
 (0)