Skip to content

Remove the redundant lexical scope for function-body brace statements. #36190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/SILGen/SILGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,12 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
auto *Parent =
DebugScopeStack.size() ? DebugScopeStack.back().getPointer() : F.getDebugScope();
auto *DS = Parent;
// Don't nest a scope for Loc under Parent unless it's actually different.
if (RegularLocation(DS->getLoc()) != RegularLocation(Loc)) {
DS = new (SGM.M)
// Don't create a pointless scope for the function body's BraceStmt.
if (!DebugScopeStack.empty())
// Don't nest a scope for Loc under Parent unless it's actually different.
if (RegularLocation(DS->getLoc()) != RegularLocation(Loc))
DS = new (SGM.M)
SILDebugScope(RegularLocation(Loc), &getFunction(), DS);
}
DebugScopeStack.emplace_back(DS, isGuardScope);
B.setCurrentDebugScope(DS);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/PlaygroundTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ class Instrumenter : InstrumenterBase {
std::pair<PatternBindingDecl *, VarDecl *>
buildPatternAndVariable(Expr *InitExpr) {
SmallString<16> NameBuf;
(Twine("tmp") + Twine(TmpNameIndex)).toVector(NameBuf);
(Twine("tmp") + Twine(TmpNameIndex++)).toVector(NameBuf);

Expr *MaybeLoadInitExpr = nullptr;

Expand Down
5 changes: 2 additions & 3 deletions test/DebugInfo/any.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ func markUsed<T>(_ t: T) {}

func main() {
// CHECK: call void @llvm.dbg.declare(metadata %Any* {{.*}}, metadata ![[S:.*]], metadata !DIExpression()), !dbg ![[DBG:.*]]
// CHECK: ![[S]] = !DILocalVariable(name: "s", {{.*}}line: [[@LINE+3]]
// CHECK: ![[SCOPE:.*]] = distinct !DILexicalBlock({{.*}}line: 5, column: 13)
// CHECK: ![[DBG]] = !DILocation(line: [[@LINE+1]], column: 7, scope: ![[SCOPE:.*]])
// CHECK: ![[S]] = !DILocalVariable(name: "s", {{.*}}line: [[@LINE+2]]
// CHECK: ![[DBG]] = !DILocation(line: [[@LINE+1]], column: 7,
var s: Any = "hello world"
var n: Any = 12
var t: Any = (1,2)
Expand Down
5 changes: 2 additions & 3 deletions test/DebugInfo/basic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ public
func foo(_ a: Int64, _ b: Int64) -> Int64 {
var a = a
var b = b
// CHECK-DAG: !DILexicalBlock(scope: ![[FOO]],{{.*}} line: [[@LINE-3]]
// CHECK-DAG: ![[ASCOPE:.*]] = !DILocation(line: [[@LINE-4]],{{.*}} scope: ![[FOO]])
// CHECK-DAG: ![[ALOC:.*]] = !DILocation(line: [[@LINE-3]],{{.*}} scope: ![[FOO]])
// Check that a is the first and b is the second argument.
// CHECK-DAG: store i64 %0, i64* [[AADDR:.*]], align
// CHECK-DAG: store i64 %1, i64* [[BADDR:.*]], align
// CHECK-DAG: [[AVAL:%.*]] = getelementptr inbounds {{.*}}, [[AMEM:.*]], i32 0, i32 0
// CHECK-DAG: [[BVAL:%.*]] = getelementptr inbounds {{.*}}, [[BMEM:.*]], i32 0, i32 0
// CHECK-DAG: call void @llvm.dbg.declare(metadata i64* [[AADDR]], metadata ![[AARG:.*]], metadata !DIExpression()), !dbg ![[ASCOPE]]
// CHECK-DAG: call void @llvm.dbg.declare(metadata i64* [[AADDR]], metadata ![[AARG:.*]], metadata !DIExpression()), !dbg ![[ALOC]]
// CHECK-DAG: call void @llvm.dbg.declare(metadata i64* [[BADDR]], metadata ![[BARG:.*]], metadata !DIExpression())
// CHECK-DAG: ![[AARG]] = !DILocalVariable(name: "a", arg: 1
// CHECK-DAG: ![[BARG]] = !DILocalVariable(name: "b", arg: 2
Expand Down
2 changes: 0 additions & 2 deletions test/DebugInfo/columns.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ public func foo(_ a: Int64, _ b: Int64) -> Int64 { // line 5
}

// CHECK-DAG: !DISubprogram(name: "foo",{{.*}} line: 5,
// DWARF-CHECK-DAG: !DILexicalBlock({{.*}}, line: 5, column: 50)
// DWARF-CHECK-DAG: ![[DIV]] = !DILocation(line: 8, column: 17,
// DWARF-CHECK-DAG: ![[ADD]] = !DILocation(line: 8, column: 13,
// DWARF-CHECK-DAG: ![[SLT]] = !DILocation(line: 10, column: 9,
// DWARF-CHECK-DAG: !DILexicalBlock({{.*}}, line: 10, column: 14)
// DWARF-CHECK-DAG: ![[SUB]] = !DILocation(line: 12, column: 14,

// CV-CHECK-DAG: !DILexicalBlock({{.*}}, line: 5)
// CV-CHECK-DAG: ![[DIV]] = !DILocation(line: 8, scope:
// CV-CHECK-DAG: ![[SLT]] = !DILocation(line: 10, scope:
// CV-CHECK-DAG: !DILexicalBlock({{.*}}, line: 10)
Expand Down
4 changes: 1 addition & 3 deletions test/DebugInfo/doubleinlines.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ func callCondFail(arg: Builtin.Int1, msg: Builtin.RawPointer) {
// CHECK: define hidden swiftcc void @"$s13DoubleInlines12callCondFail3arg3msgyBi1__BptF"{{.*}} !dbg ![[FUNCSCOPE:.*]] {
// CHECK: tail call void asm sideeffect "", "n"(i32 0) #3, !dbg ![[SCOPEONE:.*]]
// CHECK: ![[FUNCSCOPEOTHER:.*]] = distinct !DISubprogram(name: "condFail",{{.*}}
// CHECK: ![[SCOPEFIVE:.*]] = distinct !DILexicalBlock(scope: ![[FUNCSCOPE]], file: ![[FILE:.*]], line: 9)
// CHECK: ![[SCOPESIX:.*]] = distinct !DILexicalBlock(scope: ![[FUNCSCOPEOTHER]], file: ![[FILE]], line: 5)
// CHECK: ![[SCOPEONE]] = !DILocation(line: 0, scope: ![[SCOPETWO:.*]], inlinedAt: ![[SCOPETHREE:.*]])
// CHECK: ![[SCOPETHREE]] = !DILocation(line: 6, scope: ![[SCOPEFOUR:.*]])
// CHECK: ![[SCOPEFOUR]] = distinct !DILexicalBlock(scope: ![[SCOPEFIVE]], file: ![[FILE]], line: 10)
// CHECK: ![[SCOPEFOUR]] = distinct !DILexicalBlock(scope: ![[FUNCSCOPE]], file: !{{.*}}, line: 10)
6 changes: 3 additions & 3 deletions test/DebugInfo/guard-let-scope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// RUN: | %FileCheck %s
func f(c: AnyObject?) {
let x = c
// CHECK: sil_scope [[S1:[0-9]+]] { loc "{{.*}}":[[@LINE-2]]:23 parent
// CHECK: sil_scope [[S1:[0-9]+]] { {{.*}} parent @{{.*}}1f
// CHECK: sil_scope [[S2:[0-9]+]] { loc "{{.*}}":[[@LINE+3]]:3 parent [[S1]] }
// CHECK: debug_value %0 : $Optional<AnyObject>, let, name "x"{{.*}} scope [[S1]]
// CHECK: debug_value %6 : $AnyObject, let, name "x", {{.*}} scope [[S2]]
// CHECK: debug_value %{{.*}} : $Optional<AnyObject>, let, name "x"{{.*}} scope [[S1]]
// CHECK: debug_value %{{.*}} : $AnyObject, let, name "x", {{.*}} scope [[S2]]
guard let x = x else {
fatalError(".")
}
Expand Down
7 changes: 2 additions & 5 deletions test/DebugInfo/inlined-generics-basic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ func yes() -> Bool { return true }
}

// SIL: sil_scope [[F:.*]] { {{.*}}parent @$s1A1CC1fyyqd__lF
// SIL: sil_scope [[F1:.*]] { loc "f.swift":1:28 parent [[F]] }
// SIL: sil_scope [[F1G:.*]] { loc "f.swift":2:5 parent [[F1]] }
// SIL: sil_scope [[F1G:.*]] { loc "f.swift":2:5 parent [[F]] }
// SIL: sil_scope [[F1G1:.*]] { loc "g.swift":2:3 {{.*}}inlined_at [[F1G]] }
// SIL: sil_scope [[F1G3:.*]] { loc "g.swift":3:5 {{.*}}inlined_at [[F1G]] }
// SIL: sil_scope [[F1G3H:.*]] { loc "h.swift":1:24
// SIL-SAME: parent @{{.*}}1h{{.*}} inlined_at [[F1G3]] }
// SIL: sil_scope [[F1G3H1:.*]] { loc "h.swift":1:37
// SIL-SAME: parent [[F1G3H]] inlined_at [[F1G3]] }

#sourceLocation(file: "C.swift", line: 1)
public class C<R> {
Expand All @@ -49,7 +46,7 @@ public class C<R> {
public func f<S>(_ s: S) {
// SIL: debug_value_addr %0 : $*S, let, name "s", argno 1,{{.*}} scope [[F]]
// SIL: function_ref {{.*}}yes{{.*}} scope [[F1G1]]
// SIL: function_ref {{.*}}use{{.*}} scope [[F1G3H1]]
// SIL: function_ref {{.*}}use{{.*}} scope [[F1G3H]]
// IR: dbg.value(metadata %swift.type* %S, metadata ![[MD_1_0:[0-9]+]]
// IR: dbg.value(metadata %swift.opaque* %0, metadata ![[S:[0-9]+]]
// IR: dbg.value(metadata %swift.opaque* %0, metadata ![[GS_T:[0-9]+]]
Expand Down
8 changes: 2 additions & 6 deletions test/DebugInfo/inlinedAt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,10 @@ public func f(_ i : Int) -> Int { // 301
// CHECK: ![[G:.*]] = distinct !DISubprogram(name: "g",

// CHECK: ![[L3:.*]] = !DILocation(line: 302, column: 10,
// CHECK-SAME: scope: ![[F_SCOPE:.*]])
// CHECK: ![[F_SCOPE]] = distinct !DILexicalBlock(scope: ![[F]],
// CHECK-SAME: line: 301, column: 33)
// CHECK: ![[G_SCOPE:.*]] = distinct !DILexicalBlock(scope: ![[G]],
// CHECK-SAME: line: 201, column: 26)
// CHECK-SAME: scope: ![[F:.*]])
// CHECK: ![[H:.*]] = distinct !DISubprogram(name: "h",
// CHECK: ![[L1]] = !DILocation(line: 101, column: 8, scope: ![[H]],
// CHECK-SAME: inlinedAt: ![[L2:.*]])
// CHECK: ![[L2]] = !DILocation(line: 203, column: 10, scope: ![[G_SCOPE]],
// CHECK: ![[L2]] = !DILocation(line: 203, column: 10, scope: ![[G]],
// CHECK-SAME: inlinedAt: ![[L3]])

8 changes: 3 additions & 5 deletions test/DebugInfo/inlinescopes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ func transparent(_ x: Int64) -> Int64 { return noinline(x) }

@inline(__always)
func inlined(_ x: Int64) -> Int64 {
// CHECK-DAG: ![[CALL]] = !DILocation(line: [[@LINE+2]], column: {{.*}}, scope: ![[SCOPE:.*]], inlinedAt: ![[INLINED:.*]])
// CHECK-DAG: ![[SCOPE:.*]] = distinct !DILexicalBlock(
// CHECK-DAG: ![[CALL]] = !DILocation(line: [[@LINE+3]], column: {{.*}}, scope: ![[SCOPE:.*]], inlinedAt: ![[INLINED:.*]])
// Check if the inlined and removed function still has the correct linkage name.
// CHECK-DAG: ![[SCOPE]] = distinct !DISubprogram(name: "inlined", linkageName: "$s4main7inlinedys5Int64VADF"
let result = transparent(x)
// TRANSPARENT-CHECK-NOT: !DISubprogram(name: "transparent"
return result
}
// CHECK-DAG: !DIGlobalVariable(name: "y",{{.*}} file: ![[TOPLEVEL]],{{.*}} line: [[@LINE+1]]
public let y = inlined(x)

// Check if the inlined and removed function still has the correct linkage name.
// CHECK-DAG: !DISubprogram(name: "inlined", linkageName: "$s4main7inlinedys5Int64VADF"
6 changes: 3 additions & 3 deletions test/DebugInfo/mandatory-inlining-ownership.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// RUN: -sil-print-after=mandatory-inlining \
// RUN: -Xllvm -sil-print-debuginfo -o /dev/null 2>&1 | %FileCheck %s

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

import os

Expand Down
7 changes: 3 additions & 4 deletions test/DebugInfo/returnlocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,9 @@ public class Class1 {
public required init?() {
print("hello")
// CHECK_INIT: call {{.*}}@"$ss5print_9separator10terminatoryypd_S2StF"{{.*}}, !dbg [[printLoc:![0-9]+]]
// CHECK_INIT: ret i{{32|64}} 0, !dbg [[retnLoc:![0-9]+]]

// CHECK_INIT: [[retnLoc]] = !DILocation(line: 0
// CHECK_INIT: [[printLoc]] = !DILocation(line: [[@LINE-5]]
// FIXME: Why doesn't ret have the correct line number?
// CHECK_INIT: ret i{{32|64}} 0, !dbg [[printLoc]]
// CHECK_INIT: [[printLoc]] = !DILocation(line: [[@LINE-4]]
return nil
}
}
6 changes: 3 additions & 3 deletions test/DebugInfo/transparent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use(z)
// CHECK-NEXT: !dbg ![[ZERO:[0-9]+]]
// CHECK-NEXT: }

// CHECK: ![[FILE:[0-9]+]] = {{.*}}"<compiler-generated>"
// CHECK: ![[SP]] = {{.*}}name: "transparent"
// CHECK-SAME: file: ![[FILE:[0-9]+]]
// CHECK: ![[SP]] = distinct !DISubprogram({{.*}}name: "transparent"
// CHECK-SAME: file: ![[FILE:[0-9]+]]
// CHECK: ![[FILE]] = {{.*}}"<compiler-generated>"
// CHECK-NOT: line:
// CHECK: ![[ZERO]] = !DILocation(line: 0,
38 changes: 19 additions & 19 deletions test/SILOptimizer/capturepromotion-wrong-lexicalscope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@

// CHECK: sil hidden [ossa] @$s4null19captureStackPromoteSiycyF : $@convention(thin) () -> @owned @callee_guaranteed () -> Int {
// CHECK: bb0:
// CHECK: %0 = alloc_box ${ var Int }, var, name "x", loc {{.*}}:32:7, scope 3
// CHECK: %1 = project_box %0 : ${ var Int }, 0, loc {{.*}}:32:7, scope 3
// CHECK: %2 = integer_literal $Builtin.IntLiteral, 1, loc {{.*}}:32:11, scope 3
// CHECK: %3 = metatype $@thin Int.Type, loc {{.*}}:32:11, scope 3
// CHECK: %4 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int, loc {{.*}}:32:11, scope 3
// CHECK: %5 = apply %4(%2, %3) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int, loc {{.*}}:32:11, scope 3
// CHECK: store %5 to [trivial] %1 : $*Int, loc {{.*}}:32:11, scope 3
// CHECK: %7 = copy_value %0 : ${ var Int }, loc {{.*}}:33:11, scope 3
// CHECK: %8 = project_box %7 : ${ var Int }, 0, loc {{.*}}:33:11, scope 3
// CHECK: mark_function_escape %1 : $*Int, loc {{.*}}:33:11, scope 3
// CHECK: %10 = function_ref @$s4null19captureStackPromoteSiycyFSiycfU_Tf2i_n : $@convention(thin) (Int) -> Int, loc {{.*}}:33:11, scope 3
// CHECK: %11 = load [trivial] %8 : $*Int, loc {{.*}}:33:11, scope 3
// CHECK: destroy_value %7 : ${ var Int }, loc {{.*}}:33:11, scope 3
// CHECK: %13 = partial_apply [callee_guaranteed] %10(%11) : $@convention(thin) (Int) -> Int, loc {{.*}}:33:11, scope 3
// CHECK: debug_value %13 : $@callee_guaranteed () -> Int, let, name "f", loc {{.*}}:33:7, scope 3
// CHECK: %0 = alloc_box ${ var Int }, var, name "x", loc {{.*}}:32:7, scope 2
// CHECK: %1 = project_box %0 : ${ var Int }, 0, loc {{.*}}:32:7, scope 2
// CHECK: %2 = integer_literal $Builtin.IntLiteral, 1, loc {{.*}}:32:11, scope 2
// CHECK: %3 = metatype $@thin Int.Type, loc {{.*}}:32:11, scope 2
// CHECK: %4 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int, loc {{.*}}:32:11, scope 2
// CHECK: %5 = apply %4(%2, %3) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int, loc {{.*}}:32:11, scope 2
// CHECK: store %5 to [trivial] %1 : $*Int, loc {{.*}}:32:11, scope 2
// CHECK: %7 = copy_value %0 : ${ var Int }, loc {{.*}}:33:11, scope 2
// CHECK: %8 = project_box %7 : ${ var Int }, 0, loc {{.*}}:33:11, scope 2
// CHECK: mark_function_escape %1 : $*Int, loc {{.*}}:33:11, scope 2
// CHECK: %10 = function_ref @$s4null19captureStackPromoteSiycyFSiycfU_Tf2i_n : $@convention(thin) (Int) -> Int, loc {{.*}}:33:11, scope 2
// CHECK: %11 = load [trivial] %8 : $*Int, loc {{.*}}:33:11, scope 2
// CHECK: destroy_value %7 : ${ var Int }, loc {{.*}}:33:11, scope 2
// CHECK: %13 = partial_apply [callee_guaranteed] %10(%11) : $@convention(thin) (Int) -> Int, loc {{.*}}:33:11, scope 2
// CHECK: debug_value %13 : $@callee_guaranteed () -> Int, let, name "f", loc {{.*}}:33:7, scope 2
// There used to be a begin_borrow here. We leave an emptyline here to preserve line numbers.
// CHECK: %15 = copy_value %13 : $@callee_guaranteed () -> Int, loc {{.*}}:34:10, scope 3
// CHECK: %15 = copy_value %13 : $@callee_guaranteed () -> Int, loc {{.*}}:34:10, scope 2
// There used to be an end_borrow here. We leave an emptyline here to preserve line numbers.
// CHECK: destroy_value %13 : $@callee_guaranteed () -> Int, loc {{.*}}:35:1, scope 3
// CHECK: destroy_value %0 : ${ var Int }, loc {{.*}}:35:1, scope 3
// CHECK: return %15 : $@callee_guaranteed () -> Int, loc {{.*}}:34:3, scope 3
// CHECK: destroy_value %13 : $@callee_guaranteed () -> Int, loc {{.*}}:35:1, scope 2
// CHECK: destroy_value %0 : ${ var Int }, loc {{.*}}:35:1, scope 2
// CHECK: return %15 : $@callee_guaranteed () -> Int, loc {{.*}}:34:3, scope 2
// CHECK: }


Expand Down
6 changes: 3 additions & 3 deletions test/SILOptimizer/castoptimizer-wrongscope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// RUN: -Xllvm -sil-print-after=diagnostic-constant-propagation \
// RUN: 2>&1 | %FileCheck %s

// CHECK: alloc_stack $R, loc {{.*}}, scope 2
// CHECK-NEXT: init_existential_addr {{.*}} : $*R, $Float, loc {{.*}}, scope 2
// CHECK-NEXT: copy_addr [take] %8 to [initialization] {{.*}} : $*Float, loc {{.*}}, scope 2
// CHECK: alloc_stack $R, loc {{.*}}, scope 1
// CHECK-NEXT: init_existential_addr {{.*}} : $*R, $Float, loc {{.*}}, scope 1
// CHECK-NEXT: copy_addr [take] %8 to [initialization] {{.*}} : $*Float, loc {{.*}}, scope 1

protocol R {}
extension Float: R {}
Expand Down
8 changes: 4 additions & 4 deletions test/SILOptimizer/constantprop-wrongscope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// Make sure that the destroy_addr instruction has the same scope of the
// instructions surrounding it.

// CHECK: destroy_addr %7 : $*Any, loc {{.*}}:22:19, scope 2
// CHECK: dealloc_stack %12 : $*Optional<Any>, loc {{.*}}:22:23, scope 2
// CHECK: dealloc_stack %7 : $*Any, loc {{.*}}:22:23, scope 2
// CHECK: dealloc_stack %6 : $*A, loc {{.*}}:22:7, scope 2
// CHECK: destroy_addr %7 : $*Any, loc {{.*}}:22:19, scope 1
// CHECK: dealloc_stack %12 : $*Optional<Any>, loc {{.*}}:22:23, scope 1
// CHECK: dealloc_stack %7 : $*Any, loc {{.*}}:22:23, scope 1
// CHECK: dealloc_stack %6 : $*A, loc {{.*}}:22:7, scope 1

import Foundation
func indexedSubscripting(b b: B, idx: Int, a: A) {
Expand Down
14 changes: 7 additions & 7 deletions test/SILOptimizer/definite-init-wrongscope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public class M {

// CHECK-LABEL: sil [ossa] @$s3del1MC4fromAcA12WithDelegate_p_tKcfc : $@convention(method) (@in WithDelegate, @owned M) -> (@owned M, @error Error)

// CHECK: [[I:%.*]] = integer_literal $Builtin.Int2, 1, loc {{.*}}:23:12, scope 3
// CHECK: [[V:%.*]] = load [trivial] %2 : $*Builtin.Int2, loc {{.*}}:23:12, scope 3
// CHECK: [[OR:%.*]] = builtin "or_Int2"([[V]] : $Builtin.Int2, [[I]] : $Builtin.Int2) : $Builtin.Int2, loc {{.*}}:23:12, scope 3
// CHECK: store [[OR]] to [trivial] %2 : $*Builtin.Int2, loc {{.*}}:23:12, scope 3
// CHECK: store %{{.*}} to [init] %{{.*}} : $*C, loc {{.*}}:26:20, scope 3
// CHECK: [[I:%.*]] = integer_literal $Builtin.Int2, 1, loc {{.*}}:23:12, scope 2
// CHECK: [[V:%.*]] = load [trivial] %2 : $*Builtin.Int2, loc {{.*}}:23:12, scope 2
// CHECK: [[OR:%.*]] = builtin "or_Int2"([[V]] : $Builtin.Int2, [[I]] : $Builtin.Int2) : $Builtin.Int2, loc {{.*}}:23:12, scope 2
// CHECK: store [[OR]] to [trivial] %2 : $*Builtin.Int2, loc {{.*}}:23:12, scope 2
// CHECK: store %{{.*}} to [init] %{{.*}} : $*C, loc {{.*}}:26:20, scope 2

// Make sure the dealloc_stack gets the same scope of the instructions surrounding it.

// CHECK: destroy_addr %0 : $*WithDelegate, loc {{.*}}:29:5, scope 3
// CHECK: dealloc_stack %2 : $*Builtin.Int2, loc {{.*}}:23:12, scope 3
// CHECK: destroy_addr %0 : $*WithDelegate, loc {{.*}}:29:5, scope 2
// CHECK: dealloc_stack %2 : $*Builtin.Int2, loc {{.*}}:23:12, scope 2
// CHECK: throw %{{.*}} : $Error, loc {{.*}}:23:12, scope 1
4 changes: 2 additions & 2 deletions test/SILOptimizer/di-conditional-destroy-scope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// REQUIRES: objc_interop


// CHECK: [[ADR:%.*]] = ref_element_addr %{{.*}} : $RecursibleDirectoryContentsGenerator, #RecursibleDirectoryContentsGenerator.fileSystem, loc {{.*}}:39:5, scope 2
// CHECK: [[ADR:%.*]] = ref_element_addr %{{.*}} : $RecursibleDirectoryContentsGenerator, #RecursibleDirectoryContentsGenerator.fileSystem, loc {{.*}}:39:5, scope 1
// CHECK: [[ADR_ACCESS:%.*]] = begin_access [deinit] [static] [[ADR]]
// CHECK: destroy_addr [[ADR_ACCESS]] : $*FileSystem, loc {{.*}}:39:5, scope 2
// CHECK: destroy_addr [[ADR_ACCESS]] : $*FileSystem, loc {{.*}}:39:5, scope 1


import Foundation
Expand Down
4 changes: 2 additions & 2 deletions test/SILOptimizer/stack-nesting-wrong-scope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// RUN: -Xllvm -sil-print-debuginfo -o %t -module-name red 2>&1 | %FileCheck %s

// CHECK: bb{{[0-9]+}}(%{{[0-9]+}} : @owned $Error):
// CHECK: dealloc_stack %{{[0-9]+}} : $*ThrowAddrOnlyStruct<T>, loc {{.*}}:26:68, scope 2
// CHECK: br bb{{[0-9]+}}(%{{[0-9]+}} : $Error), loc {{.*}}:26:15, scope 2
// CHECK: dealloc_stack %{{[0-9]+}} : $*ThrowAddrOnlyStruct<T>, loc {{.*}}:26:68, scope 1
// CHECK: br bb{{[0-9]+}}(%{{[0-9]+}} : $Error), loc {{.*}}:26:15, scope 1

protocol Patatino {
init()
Expand Down