Skip to content

Commit 95e3be6

Browse files
committed
Merge pull request #2288 from rudkx/verify-dealloc_stack
2 parents 69fad27 + e2cbc5b commit 95e3be6

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
14341434
"unowned_release requires unowned type to be loadable");
14351435
}
14361436
void checkDeallocStackInst(DeallocStackInst *DI) {
1437-
require(isa<AllocStackInst>(DI->getOperand()),
1437+
require(isa<SILUndef>(DI->getOperand()) ||
1438+
isa<AllocStackInst>(DI->getOperand()),
14381439
"Operand of dealloc_stack must be an alloc_stack");
14391440
}
14401441
void checkDeallocRefInst(DeallocRefInst *DI) {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %target-sil-opt -enable-sil-verify-all %s -diagnostics | FileCheck %s
2+
3+
sil_stage raw
4+
5+
import Builtin
6+
7+
class TheClass {}
8+
9+
// Ensure that when we remove the code after the apply of noreturn
10+
// function nada, we don't fail verification on a dealloc_stack with
11+
// an undef operand, but that we do later remove it in the diagnostics
12+
// passes.
13+
14+
// CHECK-LABEL: sil @unreachable_dealloc_stack
15+
sil @unreachable_dealloc_stack: $@convention(method) (@guaranteed TheClass) -> () {
16+
bb0(%0 : $TheClass):
17+
%1 = function_ref @nada : $@convention(c) @noreturn (Builtin.Int32) -> ()
18+
%2 = integer_literal $Builtin.Int32, 0
19+
// CHECK: apply{{.*}}
20+
%3 = apply %1(%2) : $@convention(c) @noreturn (Builtin.Int32) -> ()
21+
// CHECK-NEXT: unreachable
22+
// CHECK-NOT: dealloc_stack
23+
%4 = alloc_stack $TheClass
24+
store %0 to %4 : $*TheClass
25+
br bb1
26+
27+
bb1:
28+
dealloc_stack %4 : $*TheClass
29+
%5 = tuple ()
30+
return %5 : $()
31+
}
32+
33+
// CHECK-LABEL: sil @nada
34+
sil @nada : $@convention(c) @noreturn (Builtin.Int32) -> ()

0 commit comments

Comments
 (0)