Skip to content

Commit db9103c

Browse files
committed
[TypeLowering] Define "copy into" for opaque vals.
When building with opaque values enable, types which would otherwise get AddressOnlyTypeLowering instead get OpaqueValueTypeLowering. When such types need to be copied into an address, the emitCopyInto method gets called on the OpaqueValueTypeLowering. So it must be implemented. Additionally, vary its implementation based on whether the module is address-lowered. If it's not address-lowered, emit a copy-into as if the type were loadable. If it is address-lowered, emit a copy-into as if the type were address-only.
1 parent 1dcc53d commit db9103c

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1950,7 +1950,12 @@ namespace {
19501950
void emitCopyInto(SILBuilder &B, SILLocation loc,
19511951
SILValue src, SILValue dest, IsTake_t isTake,
19521952
IsInitialization_t isInit) const override {
1953-
llvm_unreachable("copy into");
1953+
if (B.getModule().useLoweredAddresses()) {
1954+
B.createCopyAddr(loc, src, dest, isTake, isInit);
1955+
} else {
1956+
SILValue value = emitLoadOfCopy(B, loc, src, isTake);
1957+
emitStoreOfCopy(B, loc, value, dest, isInit);
1958+
}
19541959
}
19551960

19561961
// OpaqueValue store cannot be decoupled from a destroy because it is not
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %target-sil-opt -enable-sil-verify-all %s -address-lowering -diagnostic-constant-propagation -type-lowering-force-opaque-value-lowering | %FileCheck %s
2+
sil_stage canonical
3+
4+
struct G<T> {
5+
var t: T
6+
}
7+
8+
// CHECK-LABEL: sil [ossa] @checked_cast_same_type : {{.*}} {
9+
// CHECK: copy_addr [take]
10+
// CHECK-LABEL: } // end sil function 'checked_cast_same_type'
11+
sil [ossa] @checked_cast_same_type : $@convention(thin) <T> () -> () {
12+
%addr_src = alloc_stack $G<T>
13+
%addr_dest = alloc_stack $G<T>
14+
apply undef<T>(%addr_src) : $@convention(thin) <U> () -> @out G<U>
15+
unconditional_checked_cast_addr G<T> in %addr_src : $*G<T> to G<T> in %addr_dest : $*G<T>
16+
apply undef<T>(%addr_dest) : $@convention(thin) <U> (@in_guaranteed G<U>) -> ()
17+
destroy_addr %addr_dest : $*G<T>
18+
dealloc_stack %addr_dest : $*G<T>
19+
dealloc_stack %addr_src : $*G<T>
20+
%retval = tuple ()
21+
return %retval : $()
22+
}

0 commit comments

Comments
 (0)