Skip to content

Commit 8da10e3

Browse files
committed
SILGen: Minimal workaround for multiple-emission bug with Clang-importer-synthesized properties on enums.
If you extend a C/ObjC enum type to conform to ErrorType, then the synthesized _code getter ends up registered as an external decl, but appears to already get synthesized due to @slavapestov's changes. I'm not sure whether this is reliable enough that we can simply stop registering the external decls, so just to keep the build from crashing, insert a check in emitExternalDecls that we didn't already emit the decl and skip emission. Low-risk workaround for rdar://problem/24287125.
1 parent db23757 commit 8da10e3

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

lib/SILGen/SILGenDecl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,14 @@ void SILGenModule::emitExternalWitnessTable(ProtocolConformance *c) {
11341134
void SILGenModule::emitExternalDefinition(Decl *d) {
11351135
switch (d->getKind()) {
11361136
case DeclKind::Func: {
1137+
auto fd = cast<FuncDecl>(d);
1138+
// FIXME: rdar://problem/24287125 causes us to emit some property accessors
1139+
// more than once. As a minimal workaround, skip emitting the function if
1140+
// the SILFunction for it already exists.
1141+
if (auto existing = getEmittedFunction(SILDeclRef(fd), NotForDefinition))
1142+
if (!existing->empty())
1143+
break;
1144+
11371145
emitFunction(cast<FuncDecl>(d));
11381146
break;
11391147
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
enum AXError {
2+
kAXErrorSuccess = 0,
3+
};

test/SILGen/objc_enum_errortype.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %target-swift-frontend -emit-silgen %s -import-objc-header %S/Inputs/objc_enum_errortype.h | FileCheck %s
2+
3+
// REQUIRES: objc_interop
4+
5+
// CHECK: sil @_TFE19objc_enum_errortypeVSC7AXErrorg5_codeSi
6+
7+
extension AXError: ErrorType { }

0 commit comments

Comments
 (0)