Skip to content

Commit afa80d9

Browse files
authored
Merge pull request #65352 from hyp/eng/5.9/e6e43c6b802cc85a1824ce2089cc71a82e34c012
[interop][SwiftToCxx] do not assert when emitting non-resilient struc…
2 parents 0dc470c + 52998d7 commit afa80d9

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

lib/PrintAsClang/PrintClangValueType.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ void ClangValueTypePrinter::printValueTypeDecl(
198198
// FIXME: Can we make some better layout than opaque layout for generic
199199
// types.
200200
} else if (!typeDecl->isResilient()) {
201-
202201
typeSizeAlign =
203202
interopContext.getIrABIDetails().getTypeSizeAlignment(typeDecl);
204-
assert(typeSizeAlign && "unknown layout for non-resilient type!");
205-
if (typeSizeAlign->size == 0) {
203+
// typeSizeAlign can be null if this is not a fixed-layout type,
204+
// e.g. it has resilient fields.
205+
if (typeSizeAlign && typeSizeAlign->size == 0) {
206206
// FIXME: How to represent 0 sized structs?
207207
return;
208208
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend %S/resilient-struct-in-cxx.swift -enable-library-evolution -module-name Structs -emit-module -emit-module-path %t/Structs.swiftmodule
4+
5+
// RUN: %target-swift-frontend %S/struct-with-opaque-layout-resilient-member-in-cxx.swift -typecheck -module-name UseStructs -clang-header-expose-decls=all-public -emit-clang-header-path %t/useStructs.h -I %t
6+
7+
8+
// RUN: %target-interop-build-clangxx -c %s -I %t -o %t/swift-structs-execution.o
9+
10+
// RUN: %target-interop-build-swift -c %S/resilient-struct-in-cxx.swift -enable-library-evolution -module-name Structs -o %t/resilient-struct-in-cxx.o -Xfrontend -entry-point-function-name -Xfrontend swiftMain2
11+
12+
// RUN: %target-interop-build-swift %S/struct-with-opaque-layout-resilient-member-in-cxx.swift -o %t/swift-structs-execution -Xlinker %t/resilient-struct-in-cxx.o -Xlinker %t/swift-structs-execution.o -module-name UseStructs -Xfrontend -entry-point-function-name -Xfrontend swiftMain -I %t
13+
14+
// RUN: %target-codesign %t/swift-structs-execution
15+
// RUN: %target-run %t/swift-structs-execution | %FileCheck --check-prefixes=CHECK,CURRENT %s
16+
17+
// REQUIRES: executable_test
18+
19+
#include <assert.h>
20+
#include "useStructs.h"
21+
22+
int main() {
23+
using namespace UseStructs;
24+
auto s = createUsesResilientSmallStruct();
25+
s.dump();
26+
// CHECK: UsesResilientSmallStruct(97,FirstSmallStruct(x: 65)
27+
return 0;
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %S/resilient-struct-in-cxx.swift -enable-library-evolution -module-name Structs -emit-module -emit-module-path %t/Structs.swiftmodule
3+
4+
// RUN: %target-swift-frontend %s -typecheck -module-name UseStructs -clang-header-expose-decls=all-public -emit-clang-header-path %t/useStructs.h -I %t
5+
// RUN: %FileCheck %s < %t/useStructs.h
6+
7+
// RUN: %check-interop-cxx-header-in-clang(%t/useStructs.h)
8+
9+
import Structs
10+
11+
public struct UsesResilientSmallStruct {
12+
let x: UInt32
13+
let y: FirstSmallStruct
14+
15+
public func dump() {
16+
print("UsesResilientSmallStruct(\(x),\(y)")
17+
}
18+
}
19+
20+
// CHECK: class SWIFT_SYMBOL("s:10UseStructs24UsesResilientSmallStructV") UsesResilientSmallStruct final {
21+
// CHECK: SWIFT_INLINE_THUNK const char * _Nonnull _getOpaquePointer() const noexcept { return _storage.getOpaquePointer(); }
22+
// CHECK: swift::_impl::OpaqueStorage _storage;
23+
24+
public func createUsesResilientSmallStruct() -> UsesResilientSmallStruct {
25+
UsesResilientSmallStruct(x: 97, y: createLargeStruct(45).firstSmallStruct)
26+
}

0 commit comments

Comments
 (0)