Skip to content

SILGen: adjust check for optional-to-optional conversion #82099

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion lib/SILGen/SILGenPoly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ ManagedValue Transform::transform(ManagedValue v,
bool inputIsOptional = (bool) inputObjectType;

CanType outputObjectType = outputSubstType.getOptionalObjectType();
bool outputIsOptional = (bool) outputObjectType;
bool outputIsOptional =
static_cast<bool>(loweredResultTy.getASTType().getOptionalObjectType());

// If the value is less optional than the desired formal type, wrap in
// an optional.
Expand Down
8 changes: 6 additions & 2 deletions test/SILGen/Inputs/module.modulemap
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module PointerAuth {
header "ptrauth_field_fptr_import.h"
}
header "ptrauth_field_fptr_import.h"
}

module Variadic {
header "variadic.h"
}
6 changes: 6 additions & 0 deletions test/SILGen/Inputs/variadic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include <stdarg.h>

#define u_vformatMessage swift_u_vformatMessage
void u_vformatMessage(int i, va_list ap);
20 changes: 20 additions & 0 deletions test/SILGen/variadic.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %swift_frontend_plain -S -emit-silgen %s -I %S/Inputs -o - -parse-as-library | %FileCheck %s

import Variadic

public func f() {
withVaList([0.0]) {
u_vformatMessage(0, $0)
}
}

// CHECK: bb0(%0 : $*(), %1 : $CVaListPointer):
// CHECK: %3 = function_ref @$sSC16u_vformatMessageyys5Int32V_s14CVaListPointerVSgtcvg : $@convention(thin) () -> @owned @callee_guaranteed (Int32, Optional<CVaListPointer>) -> ()
// CHECK: %4 = apply %3() : $@convention(thin) () -> @owned @callee_guaranteed (Int32, Optional<CVaListPointer>) -> ()
// CHECK: %5 = integer_literal $Builtin.IntLiteral, 0
// CHECK: %6 = metatype $@thin Int32.Type
// CHECK: %7 = function_ref @$ss5Int32V22_builtinIntegerLiteralABBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int32.Type) -> Int32
// CHECK: %8 = apply %7(%5, %6) : $@convention(method) (Builtin.IntLiteral, @thin Int32.Type) -> Int32
// CHECK: %9 = enum $Optional<CVaListPointer>, #Optional.some!enumelt, %1
// CHECK: %10 = begin_borrow %4
// CHECK: %11 = apply %10(%8, %9) : $@callee_guaranteed (Int32, Optional<CVaListPointer>) -> ()