Skip to content

Commit fb32936

Browse files
authored
Merge pull request #4563 from adrian-prantl/28040875
2 parents e44e0d9 + befb85e commit fb32936

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1937,7 +1937,10 @@ SILValue LifetimeChecker::handleConditionalInitAssign() {
19371937
B.setCurrentDebugScope(TheMemory.getFunction().getDebugScope());
19381938
SILType IVType =
19391939
SILType::getBuiltinIntegerType(NumMemoryElements, Module.getASTContext());
1940-
auto *ControlVariableBox = B.createAllocStack(Loc, IVType);
1940+
// Use an empty location for the alloc_stack. If Loc is variable declaration
1941+
// the alloc_stack would look like the storage of that variable.
1942+
auto *ControlVariableBox =
1943+
B.createAllocStack(RegularLocation(SourceLoc()), IVType);
19411944

19421945
// Find all the return blocks in the function, inserting a dealloc_stack
19431946
// before the return.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %target-swift-frontend %s -emit-sil -g -o - | %FileCheck %s
2+
public protocol DelegateA {}
3+
public protocol DelegateB {}
4+
public protocol WithDelegate
5+
{
6+
var delegate: DelegateA? { get }
7+
func f() throws -> Int
8+
}
9+
public enum Err: Swift.Error {
10+
case s(Int)
11+
}
12+
public class C {}
13+
public class M {
14+
let field: C
15+
var value : Int
16+
// Verify that definite initialization doesn't create a bogus description of
17+
// self pointing to the liveness bitvector.
18+
19+
// CHECK: sil @_TFC4main1McfzT4fromPS_12WithDelegate__S0_
20+
// CHECK: bb0
21+
// CHECK-NEXT: %2 = alloc_stack $Builtin.Int2
22+
// CHECK-NOT: let
23+
// CHECK-NOT: name
24+
// CHECK: scope
25+
public init(from d: WithDelegate) throws {
26+
guard let delegate = d.delegate as? DelegateB
27+
else { throw Err.s(0) }
28+
self.field = C()
29+
let i: Int = try d.f()
30+
value = i
31+
}
32+
}

0 commit comments

Comments
 (0)