Skip to content

Commit 15764ef

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 33a324e commit 15764ef

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %swift_frontend_plain -S -emit-silgen %s -I %S/Inputs -o - -parse-as-library | %FileCheck %s
2+
3+
import Variadic
4+
5+
public func f() {
6+
withVaList([0.0]) {
7+
u_vformatMessage(0, $0)
8+
}
9+
}
10+
11+
// CHECK: bb0(%0 : $*(), %1 : $CVaListPointer):
12+
// CHECK: %3 = function_ref @$sSC16u_vformatMessageyys5Int32V_s14CVaListPointerVSgtcvg : $@convention(thin) () -> @owned @callee_guaranteed (Int32, Optional<CVaListPointer>) -> ()
13+
// CHECK: %4 = apply %3() : $@convention(thin) () -> @owned @callee_guaranteed (Int32, Optional<CVaListPointer>) -> ()
14+
// CHECK: %5 = integer_literal $Builtin.IntLiteral, 0
15+
// CHECK: %6 = metatype $@thin Int32.Type
16+
// CHECK: %7 = function_ref @$ss5Int32V22_builtinIntegerLiteralABBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int32.Type) -> Int32
17+
// CHECK: %8 = apply %7(%5, %6) : $@convention(method) (Builtin.IntLiteral, @thin Int32.Type) -> Int32
18+
// CHECK: %9 = enum $Optional<CVaListPointer>, #Optional.some!enumelt, %1
19+
// CHECK: %10 = begin_borrow %4
20+
// CHECK: %11 = apply %10(%8, %9) : $@callee_guaranteed (Int32, Optional<CVaListPointer>) -> ()

0 commit comments

Comments
 (0)