Skip to content

Commit 732a6ea

Browse files
authored
[IRGen] Fix crash when using C union types with layout strings (#63983)
rdar://106056035
1 parent 0543c28 commit 732a6ea

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

lib/IRGen/GenStruct.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,9 @@ namespace {
403403
std::vector<TypeLayoutEntry *> fields;
404404
for (auto &field : getFields()) {
405405
auto fieldTy = field.getType(IGM, T);
406+
if (!fieldTy) {
407+
return IGM.typeLayoutCache.getOrCreateTypeInfoBasedEntry(*this, T);
408+
}
406409
fields.push_back(
407410
field.getTypeInfo().buildTypeLayoutEntry(IGM, fieldTy, useStructLayouts));
408411
}

test/IRGen/Inputs/union_type.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
union TestUnion {
2+
int x;
3+
char y[80];
4+
void* z;
5+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %target-swift-frontend -enable-experimental-feature LayoutStringValueWitnesses -enable-type-layout -emit-ir -import-objc-header %S/Inputs/union_type.h %s
2+
3+
struct UnionWrapper {
4+
let x: TestUnion
5+
}

0 commit comments

Comments
 (0)