Files
swift-mirror/test/DebugInfo/callexpr.swift
Nathan Hawes 94916dee92 [AST] Restore getSourceRange() on DefaultArgumentExpr.
This restores getSourceRange() on DefaultArgumentExpr after it was removed in
https://github.com/apple/swift/pull/31184.

It was originally removed to solve the issues it was causing when computing the
source range of its parent TupleExpr. To account for trailing closures we walk
back through the tuple's arguments until one with a valid location is found,
which we use as the end location. If the last argument was a DefaultArgumentExpr
though that meant the end loc would end up being the tuple's start location, so
none of the tuple's other arguments were contained in its range, triggering an
ASTVerifier assertion. Source tooling and diagnostics don't care about default
arg expression locations as nothing can reference them, but their locations are
output in the debug info. Added a regression test to catch that in future, and
updated TupleExpr::getSourceRange() to ignore them when computing the end loc.

Resolves rdar://problem/63195504.
2020-05-18 14:52:00 -07:00

27 lines
967 B
Swift

// RUN: %target-swift-frontend %s -g -emit-ir -o - | %FileCheck %s
// RUN: %target-swift-frontend %s -g -emit-ir -o - | %FileCheck --check-prefix=CHECK2 %s
func markUsed<T>(_ t: T) {}
func foo(_ a : Int64, _ b : Int64) -> Int64 {
return a+b
}
// CHECK: call {{.*}}foo{{.*}}, !dbg ![[ARG1:.*]]
// CHECK: call {{.*}}foo{{.*}}, !dbg ![[ARG2:.*]]
// CHECK: call {{.*}}foo{{.*}}, !dbg ![[OUTER:.*]]
let r = foo(
foo(1, 23), // CHECK: ![[ARG1]] = !DILocation(line: [[@LINE]],
foo(2, 42) // CHECK: ![[ARG2]] = !DILocation(line: [[@LINE]],
) // CHECK: ![[OUTER]] = !DILocation(line: [[@LINE-3]],
markUsed(r)
struct MyType {}
func bar(x: MyType = MyType()) {}
// CHECK2: call {{.*}}MyType{{.*}}, !dbg ![[DEFAULTARG:.*]]
// CHECK2: call {{.*}}bar{{.*}}, !dbg ![[BARCALL:.*]]
bar() // CHECK2: ![[DEFAULTARG]] = !DILocation(line: [[@LINE]], column: 4
// CHECK2: ![[BARCALL]] = !DILocation(line: [[@LINE-1]], column: 1