Skip to content

Commit 95d2479

Browse files
committed
[DebugInfo] Fix verifier crash for complex switch
An alloc_stack, just like a debug_value, should ignore location overrides for their variable. Fixes #73338 rdar://127348128
1 parent 6136183 commit 95d2479

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,9 @@ class SILBuilder {
423423
#else
424424
(void)skipVarDeclAssert;
425425
#endif
426+
// Don't apply location overrides on variables.
427+
if (Var && !Var->Loc)
428+
Var->Loc = Loc;
426429
return insert(AllocStackInst::create(
427430
getSILDebugLocation(Loc, true), elementType, getFunction(),
428431
substituteAnonymousArgs(Name, Var, Loc), dynamic, isLexical,

test/DebugInfo/case-match-vars.swift

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %{python} %utils/split_file.py -o %t %s
3+
4+
// RUN: %target-swift-frontend -module-name a -parse-as-library -emit-ir -g %t/Seq.swift %t/A.swift | %FileCheck %s
5+
6+
// This code used to trigger the verifier.
7+
// https://github.com/apple/swift/issues/73338
8+
9+
// BEGIN Seq.swift
10+
struct A<Element: Equatable>: ExpressibleByArrayLiteral, Equatable {
11+
var base: Element?
12+
init(arrayLiteral elements: Element...) {}
13+
}
14+
struct B<Element: Equatable>: ExpressibleByArrayLiteral, Equatable {
15+
var first: Element?
16+
init(arrayLiteral elements: Element...) {}
17+
}
18+
19+
// BEGIN A.swift
20+
enum E<T: P> {
21+
case a(A<T.ID>)
22+
case b(B<T.ID>)
23+
case c
24+
25+
static func ==(lhs: Self, rhs: Self) -> Bool {
26+
switch (lhs, rhs) {
27+
case (.a([]), .c), (.c, .a([])),
28+
(.b([]), .c), (.c, .b([])):
29+
return true
30+
default:
31+
return false
32+
}
33+
}
34+
}
35+
public protocol P {
36+
associatedtype ID: Equatable
37+
}
38+
39+
// The [] expressions should be available in the debugger
40+
41+
// CHECK: !DILocalVariable(name: "$_0", {{.+}} line: 9
42+
// CHECK: !DILocalVariable(name: "$_1", {{.+}} line: 9
43+
// CHECK: !DILocalVariable(name: "$_2", {{.+}} line: 8
44+
// CHECK: !DILocalVariable(name: "$_3", {{.+}} line: 8
45+

0 commit comments

Comments
 (0)