Skip to content

Commit 73fd67b

Browse files
authored
Merge pull request #85284 from eeckstein/fix-static-enums
IRGen: don't crash when emitting a statically initialized global enum with a `StaticBigInt` payload
2 parents 457a2d3 + 3150a33 commit 73fd67b

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lib/IRGen/GenConstant.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,13 @@ Explosion irgen::emitConstantValue(IRGenModule &IGM, SILValue operand,
269269
strategy.emitValueInjection(IGM, builder, ei->getElement(), data, out);
270270
return replaceUnalignedIntegerValues(IGM, std::move(out));
271271
} else if (auto *ILI = dyn_cast<IntegerLiteralInst>(operand)) {
272+
if (ILI->getType().is<BuiltinIntegerLiteralType>()) {
273+
auto pair = emitConstantIntegerLiteral(IGM, ILI);
274+
Explosion e;
275+
e.add(pair.Data);
276+
e.add(pair.Flags);
277+
return e;
278+
}
272279
return emitConstantInt(IGM, ILI);
273280
} else if (auto *FLI = dyn_cast<FloatLiteralInst>(operand)) {
274281
return emitConstantFP(IGM, FLI);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %target-build-swift -parse-as-library -O %s -module-name=test -emit-sil | %FileCheck %s
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %target-build-swift -parse-as-library -O -module-name=test %s -o %t/a.out
5+
// RUN: %target-run %t/a.out | %FileCheck %s -check-prefix=CHECK-OUTPUT
6+
7+
// REQUIRES: executable_test,swift_stdlib_no_asserts,optimized_stdlib
8+
// UNSUPPORTED: use_os_stdlib
9+
10+
11+
@available(SwiftStdlib 5.8, *)
12+
public enum StaticIntStringEnum {
13+
case s(StaticString)
14+
case i(StaticBigInt)
15+
16+
// CHECK-LABEL: sil_global hidden @$s4test19StaticIntStringEnumO1xACvpZ : $StaticIntStringEnum = {
17+
static var x = Self.i(27)
18+
}
19+
20+
@available(SwiftStdlib 5.8, *)
21+
@main
22+
struct Main {
23+
static func main() {
24+
// CHECK-OUTPUT: StaticIntStringEnum: i(+0x1B)
25+
print("StaticIntStringEnum:", StaticIntStringEnum.x)
26+
}
27+
}
28+

0 commit comments

Comments
 (0)