Skip to content

Commit 7869d94

Browse files
authored
Merge pull request #30335 from mikeash/fix-enumtypeinfobuilder-dangling-reference
2 parents 72fba7d + faa2bf2 commit 7869d94

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

stdlib/public/Reflection/TypeLowering.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ class ExistentialTypeInfoBuilder {
449449
}
450450

451451
if (!isa<ReferenceTypeInfo>(SuperclassTI)) {
452-
DEBUG_LOG(fprintf(stderr, "Superclass not a reference type: ")
452+
DEBUG_LOG(fprintf(stderr, "Superclass not a reference type: ");
453453
SuperclassTI->dump());
454454
Invalid = true;
455455
continue;
@@ -1134,7 +1134,10 @@ class EnumTypeInfoBuilder {
11341134
}
11351135

11361136
void addCase(const std::string &Name) {
1137-
Cases.push_back({Name, /*offset=*/0, /*value=*/-1, nullptr, TypeInfo()});
1137+
// FieldInfo's TI field is a reference, so give it a reference to a value
1138+
// that stays alive forever.
1139+
static TypeInfo emptyTI;
1140+
Cases.push_back({Name, /*offset=*/0, /*value=*/-1, nullptr, emptyTI});
11381141
}
11391142

11401143
void addCase(const std::string &Name, const TypeRef *TR,
@@ -1566,7 +1569,7 @@ const TypeInfo *TypeConverter::getClassInstanceTypeInfo(const TypeRef *TR,
15661569
unsigned start) {
15671570
auto FD = getBuilder().getFieldTypeInfo(TR);
15681571
if (FD == nullptr) {
1569-
DEBUG_LOG(fprintf(stderr, "No field descriptor: ";) TR->dump());
1572+
DEBUG_LOG(fprintf(stderr, "No field descriptor: "); TR->dump());
15701573
return nullptr;
15711574
}
15721575

0 commit comments

Comments
 (0)