Skip to content

Commit 60ae044

Browse files
author
Joe Shajrawi
authored
Merge pull request #7748 from shajrawi/globals_load_of_copy
Support load and load of copy for globals in opaque value types
2 parents 16eb32f + acc33e8 commit 60ae044

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

lib/SIL/TypeLowering.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,22 +1118,12 @@ namespace {
11181118

11191119
// --- Same as NonTrivialLoadableTypeLowering
11201120

1121-
SILValue emitLoadOfCopy(SILBuilder &B, SILLocation loc,
1122-
SILValue addr, IsTake_t isTake) const override {
1123-
llvm_unreachable("load copy");
1124-
}
1125-
11261121
void emitStoreOfCopy(SILBuilder &B, SILLocation loc,
11271122
SILValue newValue, SILValue addr,
11281123
IsInitialization_t isInit) const override {
11291124
llvm_unreachable("store copy");
11301125
}
11311126

1132-
SILValue emitLoad(SILBuilder &B, SILLocation loc, SILValue addr,
1133-
LoadOwnershipQualifier qual) const override {
1134-
llvm_unreachable("store");
1135-
}
1136-
11371127
// --- Same as LeafLoadableTypeLowering.
11381128

11391129
SILValue emitLoweredCopyValue(SILBuilder &B, SILLocation loc,

lib/SILGen/SILGenLValue.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,7 +2039,7 @@ ManagedValue SILGenFunction::emitLoad(SILLocation loc, SILValue addr,
20392039
(isGuaranteedValid ? C.isGuaranteedPlusZeroOk()
20402040
: C.isImmediatePlusZeroOk()));
20412041

2042-
if (rvalueTL.isAddressOnly()) {
2042+
if (rvalueTL.isAddressOnly() && silConv.useLoweredAddresses()) {
20432043
// If the client is cool with a +0 rvalue, the decl has an address-only
20442044
// type, and there are no conversions, then we can return this as a +0
20452045
// address RValue.
@@ -2296,7 +2296,7 @@ SILValue SILGenFunction::emitSemanticLoad(SILLocation loc,
22962296
const TypeLowering &rvalueTL,
22972297
IsTake_t isTake) {
22982298
assert(srcTL.getLoweredType().getAddressType() == src->getType());
2299-
assert(rvalueTL.isLoadable());
2299+
assert(rvalueTL.isLoadable() || !silConv.useLoweredAddresses());
23002300

23012301
// Easy case: the types match.
23022302
if (srcTL.getLoweredType() == rvalueTL.getLoweredType()) {

test/SILGen/opaque_values_silgen.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,29 @@ func s170____force_convert<T>() -> T {
264264
let x : T = 42 as! T
265265
return x
266266
}
267+
268+
// Tests supporting function for s190___return_foo_var - cast and return of protocol
269+
// ---
270+
// CHECK-LABEL: sil hidden @_T020opaque_values_silgen21s180_______return_fooAA3Foo_pyF : $@convention(thin) () -> @out Foo {
271+
// CHECK: bb0:
272+
// CHECK: [[INT_LIT:%.*]] = integer_literal $Builtin.Int2048, 42
273+
// CHECK: [[INT_ARG:%.*]] = apply %{{.*}}([[INT_LIT]], [[INT_TYPE]]) : $@convention(method) (Builtin.Int2048, @thin Int.Type) -> Int
274+
// CHECK: [[INT_CAST:%.*]] = unconditional_checked_cast_opaque [[INT_ARG]] : $Int to $Foo
275+
// CHECK: return [[INT_CAST]] : $Foo
276+
// CHECK-LABEL: } // end sil function '_T020opaque_values_silgen21s180_______return_fooAA3Foo_pyF'
277+
func s180_______return_foo() -> Foo {
278+
return 42 as! Foo
279+
}
280+
var foo_var : Foo = s180_______return_foo()
281+
282+
// Tests return of global variables by doing a load of copy
283+
// ---
284+
// CHECK-LABEL: sil hidden @_T020opaque_values_silgen21s190___return_foo_varAA3Foo_pyF : $@convention(thin) () -> @out Foo {
285+
// CHECK: bb0:
286+
// CHECK: [[GLOBAL:%.*]] = global_addr {{.*}} : $*Foo
287+
// CHECK: [[LOAD_GLOBAL:%.*]] = load [copy] [[GLOBAL]] : $*Foo
288+
// CHECK: return [[LOAD_GLOBAL]] : $Foo
289+
// CHECK-LABEL: } // end sil function '_T020opaque_values_silgen21s190___return_foo_varAA3Foo_pyF'
290+
func s190___return_foo_var() -> Foo {
291+
return foo_var
292+
}

0 commit comments

Comments
 (0)