Skip to content

Commit 8359c4c

Browse files
Merge pull request swiftlang#39763 from adrian-prantl/83769198
Enter a fresh lexical scope for the enlosing brace statment of a func…
2 parents 83a79a5 + a6a4b1b commit 8359c4c

16 files changed

+84
-59
lines changed

lib/SILGen/SILGenFunction.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -590,12 +590,9 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
590590
auto *Parent = DebugScopeStack.size() ? DebugScopeStack.back().getPointer()
591591
: F.getDebugScope();
592592
auto *DS = Parent;
593-
// Don't create a pointless scope for the function body's BraceStmt.
594-
if (!DebugScopeStack.empty())
595-
// Don't nest a scope for Loc under Parent unless it's actually different.
596-
if (RegularLocation(DS->getLoc()) != RegularLocation(Loc))
597-
DS = new (SGM.M)
598-
SILDebugScope(RegularLocation(Loc), &getFunction(), DS);
593+
// Don't nest a scope for Loc under Parent unless it's actually different.
594+
if (RegularLocation(DS->getLoc()) != RegularLocation(Loc))
595+
DS = new (SGM.M) SILDebugScope(RegularLocation(Loc), &getFunction(), DS);
599596
DebugScopeStack.emplace_back(DS, isBindingScope);
600597
B.setCurrentDebugScope(DS);
601598
}

test/DebugInfo/doubleinlines.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ func callCondFail(arg: Builtin.Int1, msg: Builtin.RawPointer) {
1010
condFail(arg: arg, msg: msg)
1111
}
1212

13-
// CHECK: define hidden swiftcc void @"$s13DoubleInlines12callCondFail3arg3msgyBi1__BptF"{{.*}} !dbg ![[FUNCSCOPE:.*]] {
13+
// CHECK: define hidden swiftcc void @"$s13DoubleInlines12callCondFail3arg3msgyBi1__BptF"{{.*}} !dbg ![[FUNC:.*]] {
1414
// CHECK: tail call void asm sideeffect "", "n"(i32 0) #3, !dbg ![[SCOPEONE:.*]]
1515
// CHECK: ![[FUNCSCOPEOTHER:.*]] = distinct !DISubprogram(name: "condFail",{{.*}}
16+
// CHECK: ![[FUNCSCOPE:[0-9]+]] = distinct !DILexicalBlock(scope: ![[FUNC]],
1617
// CHECK: ![[SCOPEONE]] = !DILocation(line: 0, scope: ![[SCOPETWO:.*]], inlinedAt: ![[SCOPETHREE:.*]])
1718
// CHECK: ![[SCOPETHREE]] = !DILocation(line: 6, scope: ![[SCOPEFOUR:.*]])
1819
// CHECK: ![[SCOPEFOUR]] = distinct !DILexicalBlock(scope: ![[FUNCSCOPE]], file: !{{.*}}, line: 10)

test/DebugInfo/guard-let-scope.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
func f(c: AnyObject?) {
44
let x = c
55
// CHECK: sil_scope [[S1:[0-9]+]] { {{.*}} parent @{{.*}}1f
6-
// CHECK: sil_scope [[S2:[0-9]+]] { loc "{{.*}}":[[@LINE+3]]:17 parent [[S1]] }
7-
// CHECK: debug_value %{{.*}} : $Optional<AnyObject>, let, name "x"{{.*}} scope [[S1]]
8-
// CHECK: debug_value %{{.*}} : $AnyObject, let, name "x", {{.*}} scope [[S2]]
6+
// CHECK: sil_scope [[S2:[0-9]+]] { {{.*}} parent [[S1]] }
7+
// CHECK: sil_scope [[S3:[0-9]+]] { loc "{{.*}}":[[@LINE+3]]:17 parent [[S2]] }
8+
// CHECK: debug_value %{{.*}} : $Optional<AnyObject>, let, name "x"{{.*}} scope [[S2]]
9+
// CHECK: debug_value %{{.*}} : $AnyObject, let, name "x", {{.*}} scope [[S3]]
910
guard let x = x else {
1011
fatalError(".")
1112
}

test/DebugInfo/inlined-generics-basic.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ func yes() -> Bool { return true }
2929
}
3030

3131
// SIL: sil_scope [[F:.*]] { {{.*}}parent @$s1A1CC1fyyqd__lF
32-
// SIL: sil_scope [[F1G:.*]] { loc "f.swift":2:5 parent [[F]] }
32+
// SIL: sil_scope [[F1:.*]] { {{.*}}parent [[F]] }
33+
// SIL: sil_scope [[F1G:.*]] { loc "f.swift":2:5 parent [[F1]] }
3334
// SIL: sil_scope [[F1G1:.*]] { loc "g.swift":2:3 {{.*}}inlined_at [[F1G]] }
3435
// SIL: sil_scope [[F1G3:.*]] { loc "g.swift":3:5 {{.*}}inlined_at [[F1G]] }
3536
// SIL: sil_scope [[F1G3H:.*]] { loc "h.swift":1:24
3637
// SIL-SAME: parent @{{.*}}1h{{.*}} inlined_at [[F1G3]] }
38+
// SIL: sil_scope [[F1G3H1:.*]] { {{.*}} parent [[F1G3H]] inlined_at [[F1G3]] }
3739

3840
#sourceLocation(file: "C.swift", line: 1)
3941
public class C<R> {
@@ -46,7 +48,7 @@ public class C<R> {
4648
public func f<S>(_ s: S) {
4749
// SIL: debug_value %0 : $*S, let, name "s", argno 1, expr op_deref, {{.*}} scope [[F]]
4850
// SIL: function_ref {{.*}}yes{{.*}} scope [[F1G1]]
49-
// SIL: function_ref {{.*}}use{{.*}} scope [[F1G3H]]
51+
// SIL: function_ref {{.*}}use{{.*}} scope [[F1G3H1]]
5052
// IR: dbg.value(metadata %swift.type* %S, metadata ![[MD_1_0:[0-9]+]]
5153
// IR: dbg.value(metadata %swift.opaque* %0, metadata ![[S:[0-9]+]]
5254
// IR: dbg.value(metadata %swift.opaque* %0, metadata ![[GS_T:[0-9]+]]

test/DebugInfo/inlinedAt.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ public func f(_ i : Int) -> Int { // 301
4242

4343
// CHECK: ![[L3:.*]] = !DILocation(line: 302, column: 10,
4444
// CHECK-SAME: scope: ![[F:.*]])
45+
// CHECK: ![[G1:[0-9]+]] = distinct !DILexicalBlock(scope: ![[G]],
4546
// CHECK: ![[H:.*]] = distinct !DISubprogram(name: "h",
4647
// CHECK: ![[L1]] = !DILocation(line: 101, column: 8, scope: ![[H]],
4748
// CHECK-SAME: inlinedAt: ![[L2:.*]])
48-
// CHECK: ![[L2]] = !DILocation(line: 203, column: 10, scope: ![[G]],
49+
// CHECK: ![[L2]] = !DILocation(line: 203, column: 10, scope: ![[G1]],
4950
// CHECK-SAME: inlinedAt: ![[L3]])
5051

test/DebugInfo/inlinescopes.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ func transparent(_ x: Int64) -> Int64 { return noinline(x) }
2424

2525
@inline(__always)
2626
func inlined(_ x: Int64) -> Int64 {
27-
// CHECK-DAG: ![[CALL]] = !DILocation(line: [[@LINE+3]], column: {{.*}}, scope: ![[SCOPE:.*]], inlinedAt: ![[INLINED:.*]])
27+
// CHECK-DAG: ![[CALL]] = !DILocation(line: [[@LINE+4]], column: {{.*}}, scope: ![[SCOPE:.*]], inlinedAt: ![[INLINED:.*]])
2828
// Check if the inlined and removed function still has the correct linkage name.
29-
// CHECK-DAG: ![[SCOPE]] = distinct !DISubprogram(name: "inlined", linkageName: "$s4main7inlinedys5Int64VADF"
29+
// CHECK-DAG: ![[SCOPE]] = distinct !DILexicalBlock(scope: ![[INLINED:[0-9]+]],
30+
// CHECK-DAG: ![[INLINED]] = distinct !DISubprogram(name: "inlined", linkageName: "$s4main7inlinedys5Int64VADF"
3031
let result = transparent(x)
3132
// TRANSPARENT-CHECK-NOT: !DISubprogram(name: "transparent"
3233
return result

test/DebugInfo/mandatory-inlining-ownership.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
// RUN: -sil-print-after=mandatory-inlining \
55
// RUN: -Xllvm -sil-print-debuginfo -o /dev/null 2>&1 | %FileCheck %s
66

7-
// CHECK: begin_borrow {{.*}} : $OSLog, loc {{.*}}, scope 4
8-
// CHECK: tuple (), loc {{.*}}, scope 4
9-
// CHECK: end_borrow %9 : $OSLog, loc {{.*}}, scope 4
7+
// CHECK: begin_borrow {{.*}} : $OSLog, loc {{.*}}, scope 5
8+
// CHECK: tuple (), loc {{.*}}, scope 5
9+
// CHECK: end_borrow %9 : $OSLog, loc {{.*}}, scope 5
1010

1111
import os
1212

test/DebugInfo/returnlocation.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,9 @@ public class Class1 {
185185
print("hello")
186186
// CHECK_INIT: call {{.*}}@"$ss5print_9separator10terminatoryypd_S2StF"{{.*}}, !dbg [[printLoc:![0-9]+]]
187187
// FIXME: Why doesn't ret have the correct line number?
188-
// CHECK_INIT: ret i{{32|64}} 0, !dbg [[printLoc]]
189-
// CHECK_INIT: [[printLoc]] = !DILocation(line: [[@LINE-4]]
188+
// CHECK_INIT: ret i{{32|64}} 0, !dbg ![[RETLOC:[0-9]+]]
189+
// CHECK_INIT: [[RETLOC]] = !DILocation(line: 0
190+
// CHECK_INIT: [[printLoc]] = !DILocation(line: [[@LINE-5]]
190191
return nil
191192
}
192193
}

test/DebugInfo/shadowed-arg.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-swift-frontend %s -parse-as-library -emit-ir -g -o - \
2+
// RUN: -module-name main | %FileCheck %s
3+
// RUN: %target-swift-frontend %s -parse-as-library -emit-sil \
4+
// RUN: -Xllvm -sil-print-debuginfo -o - \
5+
// RUN: -module-name main | %FileCheck %s --check-prefix=SIL
6+
7+
// The variable i and the argument i must be in different scopes or the debugger
8+
// doesn't know which one shadows the other.
9+
public func f(i: Int) {
10+
let i = [i, i]
11+
print(i)
12+
}
13+
14+
// CHECK: ![[S1:[0-9]+]] = distinct !DISubprogram(name: "f",
15+
// CHECK: !DILocalVariable(name: "i", arg: 1, scope: ![[S1]],
16+
// CHECK: !DILocalVariable(name: "i", scope: ![[S2:[0-9]+]],
17+
// CHECK: ![[S2]] = distinct !DILexicalBlock(scope: ![[S1]],
18+
// SIL: sil_scope [[S1:[0-9]+]] { {{.*}} parent @$s4main1f1iySi_tF
19+
// SIL: sil_scope [[S2:[0-9]+]] { {{.*}} parent [[S1]] }
20+
// SIL: debug_value %0 : $Int, let, name "i", argno 1,{{.*}}, scope [[S1]]
21+
// SIL: debug_value {{.*}} : $Array<Int>, let, name "i", {{.*}}, scope [[S2]]

test/DebugInfo/transparent.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use(z)
2121
// CHECK-NEXT: !dbg ![[ZERO:[0-9]+]]
2222
// CHECK-NEXT: }
2323

24+
// CHECK: ![[FILE:[0-9]+]] = {{.*}}"<compiler-generated>"
2425
// CHECK: ![[SP]] = distinct !DISubprogram({{.*}}name: "transparent"
25-
// CHECK-SAME: file: ![[FILE:[0-9]+]]
26-
// CHECK: ![[FILE]] = {{.*}}"<compiler-generated>"
26+
// CHECK-SAME: file: ![[FILE]]
2727
// CHECK-NOT: line:
2828
// CHECK: ![[ZERO]] = !DILocation(line: 0,

0 commit comments

Comments
 (0)