diff --git a/lib/SILGen/SILGenPoly.cpp b/lib/SILGen/SILGenPoly.cpp index 1f1d26ff86c62..4d09642f4782c 100644 --- a/lib/SILGen/SILGenPoly.cpp +++ b/lib/SILGen/SILGenPoly.cpp @@ -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(loweredResultTy.getASTType().getOptionalObjectType()); // If the value is less optional than the desired formal type, wrap in // an optional. diff --git a/test/SILGen/Inputs/module.modulemap b/test/SILGen/Inputs/module.modulemap index 53cc761b69592..c7ffc93319ec6 100644 --- a/test/SILGen/Inputs/module.modulemap +++ b/test/SILGen/Inputs/module.modulemap @@ -1,3 +1,7 @@ module PointerAuth { - header "ptrauth_field_fptr_import.h" - } + header "ptrauth_field_fptr_import.h" +} + +module Variadic { + header "variadic.h" +} diff --git a/test/SILGen/Inputs/variadic.h b/test/SILGen/Inputs/variadic.h new file mode 100644 index 0000000000000..61d5f968b781d --- /dev/null +++ b/test/SILGen/Inputs/variadic.h @@ -0,0 +1,6 @@ +#pragma once + +#include + +#define u_vformatMessage swift_u_vformatMessage +void u_vformatMessage(int i, va_list ap); diff --git a/test/SILGen/variadic.swift b/test/SILGen/variadic.swift new file mode 100644 index 0000000000000..4f8226492805d --- /dev/null +++ b/test/SILGen/variadic.swift @@ -0,0 +1,18 @@ +// RUN: %swift_frontend_plain -emit-silgen %s -I %S/Inputs -o - -parse-as-library -verify | %FileCheck %s + +import Variadic + +public func f() { + withVaList([0.0]) { + u_vformatMessage(0, $0) + } +} + + // closure #1 in f() +// CHECK: bb0(%0 : $*(), %1 : $CVaListPointer): + // function_ref u_vformatMessage.getter +// CHECK: [[PROJECTION:%.*]] = function_ref @$sSC16u_vformatMessageyys5Int32V_s14CVaListPointerVSgtcvg : $@convention(thin) () -> @owned @callee_guaranteed (Int32, Optional) -> () +// CHECK: [[FUNCTION:%.*]] = apply [[PROJECTION]]() : $@convention(thin) () -> @owned @callee_guaranteed (Int32, Optional) -> () +// CHECK: [[VALIST:%.*]] = enum $Optional, #Optional.some!enumelt, %1 +// CHECK: [[BORROW:%.*]] = begin_borrow [[FUNCTION]] +// CHECK: {{.*}} = apply [[BORROW]]({{.*}}, [[VALIST]]) : $@callee_guaranteed (Int32, Optional) -> ()