Skip to content

Commit 78a72a6

Browse files
committed
SILGen: adjust check for optional-to-optional conversion
The new macro aliasing uncovered a latent issue where we would attempt to perform an optional-to-optional conversion on a type that is non-optional though may be aliased to an optional. `CVaList` is sometimes an optional pointer and would be interpreted as an optional type which would fail the assertion in the optional-to-optional conversion.
1 parent 2ba4e7f commit 78a72a6

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

lib/SILGen/SILGenPoly.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,8 @@ ManagedValue Transform::transform(ManagedValue v,
509509
bool inputIsOptional = (bool) inputObjectType;
510510

511511
CanType outputObjectType = outputSubstType.getOptionalObjectType();
512-
bool outputIsOptional = (bool) outputObjectType;
512+
bool outputIsOptional =
513+
static_cast<bool>(loweredResultTy.getASTType().getOptionalObjectType());
513514

514515
// If the value is less optional than the desired formal type, wrap in
515516
// an optional.

test/SILGen/Inputs/module.modulemap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
module PointerAuth {
2-
header "ptrauth_field_fptr_import.h"
3-
}
2+
header "ptrauth_field_fptr_import.h"
3+
}
4+
5+
module Variadic {
6+
header "variadic.h"
7+
}

test/SILGen/Inputs/variadic.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#pragma once
2+
3+
#include <stdarg.h>
4+
5+
#define u_vformatMessage swift_u_vformatMessage
6+
void u_vformatMessage(int i, va_list ap);

test/SILGen/variadic.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %swift_frontend_plain -emit-silgen %s -I %S/Inputs -o - -parse-as-library -verify | %FileCheck %s
2+
3+
import Variadic
4+
5+
public func f() {
6+
withVaList([0.0]) {
7+
u_vformatMessage(0, $0)
8+
}
9+
}
10+
11+
// closure #1 in f()
12+
// CHECK: bb0(%0 : $*(), %1 : $CVaListPointer):
13+
// function_ref u_vformatMessage.getter
14+
// CHECK: [[PROJECTION:%.*]] = function_ref @$sSC16u_vformatMessageyys5Int32V_s14CVaListPointerVSgtcvg : $@convention(thin) () -> @owned @callee_guaranteed (Int32, Optional<CVaListPointer>) -> ()
15+
// CHECK: [[FUNCTION:%.*]] = apply [[PROJECTION]]() : $@convention(thin) () -> @owned @callee_guaranteed (Int32, Optional<CVaListPointer>) -> ()
16+
// CHECK: [[VALIST:%.*]] = enum $Optional<CVaListPointer>, #Optional.some!enumelt, %1
17+
// CHECK: [[BORROW:%.*]] = begin_borrow [[FUNCTION]]
18+
// CHECK: {{.*}} = apply [[BORROW]]({{.*}}, [[VALIST]]) : $@callee_guaranteed (Int32, Optional<CVaListPointer>) -> ()

0 commit comments

Comments
 (0)