Skip to content

IRGen: fix a problem convert_function in a payload of a statically initialized enum #67983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/IRGen/GenConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ Explosion irgen::emitConstantValue(IRGenModule &IGM, SILValue operand,
return llvm::ConstantExpr::getIntToPtr(val, sTy);

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

} else if (auto *T2TFI = dyn_cast<ThinToThickFunctionInst>(operand)) {
SILType type = operand->getType();
Expand Down
33 changes: 33 additions & 0 deletions test/SILOptimizer/static_enums.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,43 @@ var optBlack: Color? = Color.black
// CHECK-LABEL: sil_global hidden @$s4test9optSalmonAA5ColorOSgvp : $Optional<Color> = {
var optSalmon: Color? = Color.rgb(r: 0xfa, g: 0x80, b: 0x72)

public final class C {
var x = 27
}

func printClass(_ c: C?) {
if let c = c {
print("\(c): \(c.x)")
} else {
print("none")
}
}


public enum FunctionEnum {
case f((C) -> ())
case i(Int)
}

// CHECK-LABEL: sil_global hidden @$s4test2feAA12FunctionEnumOvp : $FunctionEnum = {
var fe = FunctionEnum.f(printClass)

// CHECK-LABEL: sil_global private @$s4test9createArrSaySiSgGyFTv_ : $_ContiguousArrayStorage<Optional<Int>> = {
@inline(never)
func createArr() -> [Int?] {
return [ 27, 42, nil, 103 ]
}

@inline(never)
func printFunctionEnum() {
switch fe {
case .f(let f):
f(C())
case .i:
break
}
}

@main
struct Main {
static func main() {
Expand Down Expand Up @@ -260,6 +291,8 @@ struct Main {
print("optBlack:", optBlack as Any)
// CHECK-OUTPUT: optSalmon: Optional(test.Color.rgb(r: 250, g: 128, b: 114))
print("optSalmon:", optSalmon as Any)
// CHECK-OUTPUT: test.C: 27
printFunctionEnum()
}
}

Expand Down