Skip to content

Commit 3a6799b

Browse files
committed
[Test] Add failing SemanticARCOpts test.
It will be fixed in a subsequent commit.
1 parent 96331dd commit 3a6799b

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

lib/SILOptimizer/SemanticARC/CopyValueOpts.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "swift/SIL/MemAccessUtils.h"
2828
#include "swift/SIL/OwnershipUtils.h"
2929
#include "swift/SIL/Projection.h"
30+
#include "swift/SIL/Test.h"
3031

3132
using namespace swift;
3233
using namespace swift::semanticarc;
@@ -828,6 +829,20 @@ bool SemanticARCOptVisitor::tryPerformOwnedCopyValueOptimization(
828829
return true;
829830
}
830831

832+
namespace swift::test {
833+
static FunctionTest SemanticARCOptsCopyValueOptsGuaranteedValueOptTest(
834+
"semantic_arc_opts__copy_value_opts__guaranteed_value_opt",
835+
[](auto &function, auto &arguments, auto &test) {
836+
SemanticARCOptVisitor visitor(function, test.getPassManager(),
837+
*test.getDeadEndBlocks(),
838+
/*onlyMandatoryOpts=*/false);
839+
840+
visitor.performGuaranteedCopyValueOptimization(
841+
cast<CopyValueInst>(arguments.takeInstruction()));
842+
function.print(llvm::errs());
843+
});
844+
} // end namespace swift::test
845+
831846
//===----------------------------------------------------------------------===//
832847
// Top Level Entrypoint
833848
//===----------------------------------------------------------------------===//
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// RUN: not --crash %target-sil-opt -test-runner %s -o /dev/null 2>&1 | %FileCheck %s
2+
3+
sil_stage canonical
4+
5+
import Builtin
6+
import Swift
7+
8+
struct Inner {
9+
var o: Builtin.NativeObject
10+
}
11+
struct Outer {
12+
var inner: Inner
13+
}
14+
15+
// CHECK-LABEL: sil [ossa] @check_keep_copy_required_to_destroy_at_unreachable : {{.*}} {
16+
// CHECK: copy_value
17+
// CHECK-LABEL: } // end sil function 'check_keep_copy_required_to_destroy_at_unreachable'
18+
sil [ossa] @check_keep_copy_required_to_destroy_at_unreachable : $@convention(thin) (@in_guaranteed Outer) -> () {
19+
entry(%o_addr : $*Outer):
20+
%o_copy = load [copy] %o_addr : $*Outer
21+
%o_borrow = begin_borrow %o_copy : $Outer
22+
%i = struct_extract %o_borrow : $Outer, #Outer.inner
23+
%i_copy = copy_value %i : $Inner
24+
specify_test "semantic_arc_opts__copy_value_opts__guaranteed_value_opt %i_copy"
25+
(%o2_addr, %token) = begin_apply undef(%i_copy) : $@yield_once @convention(thin) (@guaranteed Inner) -> @yields @inout Outer
26+
try_apply undef(%o2_addr) : $@convention(thin) (@inout Outer) -> @error any Error, normal success, error failure
27+
28+
success(%empty : $()):
29+
end_apply %token as $()
30+
destroy_value %i_copy : $Inner
31+
end_borrow %o_borrow : $Outer
32+
destroy_value %o_copy : $Outer
33+
return undef : $()
34+
35+
failure(%error : @owned $any Error):
36+
end_borrow %o_borrow : $Outer
37+
destroy_value %error : $any Error
38+
end_apply %token as $()
39+
destroy_value [dead_end] %o_copy : $Outer
40+
unreachable
41+
}

0 commit comments

Comments
 (0)