Skip to content

Commit 0944c26

Browse files
committed
Don't try to import variants for FieldDecls
Back when we were eagerly importing struct fields, we only attempted to import fields under the names they have in the current version; previous versions and the raw name were ignored. Now that we're importing them lazily, we're passing through code that attempts to import all versions. That's a nice idea in theory, but neither ImportDecl nor the rest of the compiler was prepared for this, and so ImportDecl has started adding redundant stored properties to clang structs. This trips an assertion in IRGen. This commit returns to the old behavior of only importing struct fields under their current name by simply early-exiting from SwiftDeclConverter::VisitFieldDecl(). We can come up with a solution that imports the variants in the future. Fixes rdar://86069786.
1 parent 27dc562 commit 0944c26

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4206,6 +4206,13 @@ namespace {
42064206
if (!importedName) {
42074207
return nullptr;
42084208
}
4209+
if (correctSwiftName) {
4210+
// FIXME: We should import this as a variant, but to do that, we'll also
4211+
// need to make this a computed variable or otherwise fix how the rest
4212+
// of the compiler thinks about stored properties in imported structs.
4213+
// For now, just don't import it at all. (rdar://86069786)
4214+
return nullptr;
4215+
}
42094216

42104217
auto name = importedName.getDeclName().getBaseIdentifier();
42114218

@@ -4248,6 +4255,7 @@ namespace {
42484255

42494256
// If this is a compatibility stub, handle it as such.
42504257
if (correctSwiftName)
4258+
// FIXME: Temporarily unreachable because of check above.
42514259
markAsVariant(result, *correctSwiftName);
42524260

42534261
return result;

test/ClangImporter/ctypes_ir.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,12 @@ func testBigArrays(_ maxSize: UnsafeMutablePointer<Int8>?, _ maxSizePlusOne: Uns
4545
func testBigArrays2d(_ maxSize: UnsafeMutablePointer<IntTuple4096>?, _ maxSizePlusOne: OpaquePointer?) {
4646
useBigArray2d(maxSize, maxSizePlusOne)
4747
}
48+
49+
50+
// Make sure fields with a swift_name attribute only produce one stored
51+
// property, not two. (rdar://86069786)
52+
// CHECK-LABEL: define swiftcc void @"$s9ctypes_ir22testFieldWithSwiftName1oySo12Rdar86069786V_tF"
53+
// CHECK-SAME: (double %0)
54+
55+
public func testFieldWithSwiftName(o : Rdar86069786) {
56+
}

test/Inputs/clang-importer-sdk/usr/include/ctypes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ STDLIB_TYPEDEF(unsigned int, UInt);
196196
void noreturnFunction() __attribute__((noreturn));
197197
void couldReturnFunction() __attribute__((noreturn));
198198

199+
// Struct with an __attribute((swift_name)) field.
200+
struct Rdar86069786 {
201+
double c_name __attribute__((swift_name("swiftName")));
202+
};
203+
199204

200205
//===---
201206
// Function pointers

0 commit comments

Comments
 (0)