Skip to content

Commit d19f082

Browse files
committed
Extend @_silgen_name to apply to allocating initializers, too
This enables its use on enum and struct initializers.
1 parent c4e97bc commit d19f082

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/SIL/IR/SILDeclRef.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,15 @@ std::string SILDeclRef::mangle(ManglingKind MKind) const {
12011201
SKind);
12021202

12031203
case SILDeclRef::Kind::Allocator:
1204+
// As a special case, initializers can have manually mangled names.
1205+
// Use the SILGen name only for the original non-thunked, non-curried entry
1206+
// point.
1207+
if (auto NameA = getDecl()->getAttrs().getAttribute<SILGenNameAttr>()) {
1208+
if (!NameA->Name.empty() && !isThunk()) {
1209+
return NameA->Name.str();
1210+
}
1211+
}
1212+
12041213
return mangler.mangleConstructorEntity(cast<ConstructorDecl>(getDecl()),
12051214
/*allocating*/ true,
12061215
SKind);

test/IRGen/asmname.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,17 @@ private func PlainPrivate() { }
5151
// CHECK: define hidden void @cdecl_internal
5252
// CHECK: define hidden swiftcc void @"$s7asmname13CDeclInternal
5353
// CHECK: define internal void @cdecl_private()
54+
55+
// silgen_name on enum constructors
56+
public enum X {
57+
case left(Int64)
58+
case right(Int64)
59+
}
60+
61+
extension X {
62+
// CHECK: define{{( dllexport)?}}{{( protected)?}} swiftcc { i64, i8 } @blah_X_constructor
63+
@_silgen_name("blah_X_constructor")
64+
public init(blah: Int64) {
65+
self = .left(blah)
66+
}
67+
}

0 commit comments

Comments
 (0)