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

Merged
merged 1 commit into from
Jun 18, 2025
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
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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like the wrong place to do this. If there's an implicit level of optionality introduced around these APIs, we should track back to a place that matches that decision and have that place pass down an optional substituted type.


// 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);
18 changes: 18 additions & 0 deletions test/SILGen/variadic.swift
Original file line number Diff line number Diff line change
@@ -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<CVaListPointer>) -> ()
// CHECK: [[FUNCTION:%.*]] = apply [[PROJECTION]]() : $@convention(thin) () -> @owned @callee_guaranteed (Int32, Optional<CVaListPointer>) -> ()
// CHECK: [[VALIST:%.*]] = enum $Optional<CVaListPointer>, #Optional.some!enumelt, %1
// CHECK: [[BORROW:%.*]] = begin_borrow [[FUNCTION]]
// CHECK: {{.*}} = apply [[BORROW]]({{.*}}, [[VALIST]]) : $@callee_guaranteed (Int32, Optional<CVaListPointer>) -> ()