Skip to content

Commit b435cf3

Browse files
committed
IRGen: fix a problem conver_function in a payload of a statically initialized enum
This was a stupid oversight. The `flatten` flag needs to be passed through `convert_enum` in `irgen::emitConstantValue`. Fixes a compiler crash. rdar://113942221
1 parent d725e38 commit b435cf3

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

lib/IRGen/GenConstant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ Explosion irgen::emitConstantValue(IRGenModule &IGM, SILValue operand,
340340
return llvm::ConstantExpr::getIntToPtr(val, sTy);
341341

342342
} else if (auto *CFI = dyn_cast<ConvertFunctionInst>(operand)) {
343-
return emitConstantValue(IGM, CFI->getOperand());
343+
return emitConstantValue(IGM, CFI->getOperand(), flatten);
344344

345345
} else if (auto *T2TFI = dyn_cast<ThinToThickFunctionInst>(operand)) {
346346
SILType type = operand->getType();

test/SILOptimizer/static_enums.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,43 @@ var optBlack: Color? = Color.black
181181
// CHECK-LABEL: sil_global hidden @$s4test9optSalmonAA5ColorOSgvp : $Optional<Color> = {
182182
var optSalmon: Color? = Color.rgb(r: 0xfa, g: 0x80, b: 0x72)
183183

184+
public final class C {
185+
var x = 27
186+
}
187+
188+
func printClass(_ c: C?) {
189+
if let c = c {
190+
print("\(c): \(c.x)")
191+
} else {
192+
print("none")
193+
}
194+
}
195+
196+
197+
public enum FunctionEnum {
198+
case f((C) -> ())
199+
case i(Int)
200+
}
201+
202+
// CHECK-LABEL: sil_global hidden @$s4test2feAA12FunctionEnumOvp : $FunctionEnum = {
203+
var fe = FunctionEnum.f(printClass)
204+
184205
// CHECK-LABEL: sil_global private @$s4test9createArrSaySiSgGyFTv_ : $_ContiguousArrayStorage<Optional<Int>> = {
185206
@inline(never)
186207
func createArr() -> [Int?] {
187208
return [ 27, 42, nil, 103 ]
188209
}
189210

211+
@inline(never)
212+
func printFunctionEnum() {
213+
switch fe {
214+
case .f(let f):
215+
f(C())
216+
case .i:
217+
break
218+
}
219+
}
220+
190221
@main
191222
struct Main {
192223
static func main() {
@@ -260,6 +291,8 @@ struct Main {
260291
print("optBlack:", optBlack as Any)
261292
// CHECK-OUTPUT: optSalmon: Optional(test.Color.rgb(r: 250, g: 128, b: 114))
262293
print("optSalmon:", optSalmon as Any)
294+
// CHECK-OUTPUT: test.C: 27
295+
printFunctionEnum()
263296
}
264297
}
265298

0 commit comments

Comments
 (0)