Skip to content

Commit a9bd88a

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 b025679 commit a9bd88a

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
@@ -4251,6 +4251,13 @@ namespace {
42514251
if (!importedName) {
42524252
return nullptr;
42534253
}
4254+
if (correctSwiftName) {
4255+
// FIXME: We should import this as a variant, but to do that, we'll also
4256+
// need to make this a computed variable or otherwise fix how the rest
4257+
// of the compiler thinks about stored properties in imported structs.
4258+
// For now, just don't import it at all. (rdar://86069786)
4259+
return nullptr;
4260+
}
42544261

42554262
auto name = importedName.getDeclName().getBaseIdentifier();
42564263

@@ -4301,6 +4308,7 @@ namespace {
43014308

43024309
// If this is a compatibility stub, handle it as such.
43034310
if (correctSwiftName)
4311+
// FIXME: Temporarily unreachable because of check above.
43044312
markAsVariant(result, *correctSwiftName);
43054313

43064314
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)