Fix debug description for cases with multiple items (#32282)

* [SILGenFunction] Don't create redundant nested debug scopes

Instead of emitting:

```
sil_scope 4 { loc "main.swift":6:19 parent 3 }
sil_scope 5 { loc "main.swift":7:3 parent 4 }
sil_scope 6 { loc "main.swift":7:3 parent 5 }
sil_scope 7 { loc "main.swift":7:3 parent 5 }
sil_scope 8 { loc "main.swift":9:5 parent 4 }
```

Emit:

```
sil_scope 4 { loc "main.swift":6:19 parent 3 }
sil_scope 5 { loc "main.swift":7:3 parent 4 }
sil_scope 6 { loc "main.swift":9:5 parent 5 }
```

* [IRGenSIL] Diagnose conflicting shadow copies

If we attempt to store a value with the wrong type into a slot reserved
for a shadow copy, diagnose what went wrong.

* [SILGenPattern] Defer debug description of case variables

Create unique nested debug scopes for a switch, each of its case labels,
and each of its case bodies. This looks like:

```
  switch ... { // Enter scope 1.
    case ... : // Enter scope 2, nested within scope 1.
      <body-1> // Enter scope 3, nested within scope 2.

    case ... : // Enter scope 4, nested within scope 1.
      <body-2> // Enter scope 5, nested within scope 4.
  }
```

Use the new scope structure to defer emitting debug descriptions of case
bindings. Specifically, defer the work until we can nest the scope for a
case body under the scope for a pattern match.

This fixes SR-7973, a problem where it was impossible to inspect a case
binding in lldb when stopped at a case with multiple items.

Previously, we would emit the debug descriptions too early (in the
pattern match), leading to duplicate/conflicting descriptions. The only
reason that the ambiguous description was allowed to compile was because
the debug scopes were nested incorrectly.

rdar://41048339

* Update tests
This commit is contained in:
Vedant Kumar
2020-06-10 13:31:10 -07:00
committed by GitHub
parent 9b77762f54
commit 60ec3f1b90
20 changed files with 227 additions and 83 deletions

View File

@@ -30,29 +30,25 @@ public func mangle(s: [UnicodeScalar]) -> [UnicodeScalar] {
}
// The patterns in the first case statement each define an anonymous variable,
// which shares the storage with the expression in the switch statement. Make
// sure we emit a dbg.value once per basic block.
// which shares the storage with the expression in the switch statement.
// Do we care to expose these via lldb?
// CHECK: define {{.*}}@"$s11patternvars6mangle1sSayAA13UnicodeScalarVGAF_tFA2EXEfU_"
// CHECK: %[[VAL:[0-9]+]] = call swiftcc i32 @"$s11patternvars13UnicodeScalarV5values6UInt32Vvg"(i32 %0)
// CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %[[VAL]]
// CHECK: {{[0-9]+}}:
// CHECK: call void @llvm.dbg.value(metadata i32 %[[VAL]]
// CHECK-NOT: call void @llvm.dbg.value
// CHECK-NOT: call void asm sideeffect "", "r"
// CHECK: {{[0-9]+}}:
// CHECK: call void @llvm.dbg.value(metadata i32 %[[VAL]]
// CHECK-NOT: call void @llvm.dbg.value
// CHECK-NOT: call void asm sideeffect "", "r"
// CHECK: {{[0-9]+}}:
// CHECK: call void @llvm.dbg.value(metadata i32 %[[VAL]]
// CHECK-NOT: call void @llvm.dbg.value
// CHECK-NOT: call void asm sideeffect "", "r"
// CHECK: {{[0-9]+}}:
// CHECK: call void @llvm.dbg.value(metadata i32 %[[VAL]]
// CHECK-NOT: call void @llvm.dbg.value
// CHECK-NOT: call void asm sideeffect "", "r"