Skip to content

Rewrite testcases to reduce dependence on Swift stdlib #3908

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
Aug 1, 2016
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
1 change: 1 addition & 0 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ class IRGenSILFunction :
Alignment align(layout->getAlignment());

auto alloca = createAlloca(aggregateType, align, Name + ".debug");
ArtificialLocation AutoRestore(getDebugScope(), IGM.DebugInfo, Builder);
size_t i = 0;
for (auto val : vals) {
auto addr = Builder.CreateStructGEP(alloca, i,
Expand Down
12 changes: 12 additions & 0 deletions test/DebugInfo/guard-let.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %target-swift-frontend %s -emit-ir -g -o - | FileCheck %s
// RUN: %target-swift-frontend %s -emit-ir -g -o - | FileCheck %s --check-prefix=CHECK2
func use<T>(_ t: T) {}

public func f(_ i : Int?)
Expand All @@ -14,3 +15,14 @@ public func f(_ i : Int?)
guard let val = i else { return }
use(val)
}

public func g(_ s : String?)
{
// CHECK2: define {{.*}}@_TF4main1gFGSqSS_T_
// The shadow copy store should not have a location.
// CHECK2: getelementptr inbounds {{.*}} %s.debug, {{.*}}, !dbg ![[DBG0:.*]]
// CHECK2: ![[G:.*]] = distinct !DISubprogram(name: "g",
// CHECK2: ![[DBG0]] = !DILocation(line: 0, scope: ![[G]])
guard let val = s else { return }
use(val)
}
36 changes: 21 additions & 15 deletions test/DebugInfo/inlinescopes.swift
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
// RUN: rm -rf %t
// RUN: mkdir %t
// RUN: echo "public var x = Int64()" | %target-swift-frontend -module-name FooBar -emit-module -o %t -
// RUN: echo "public var x = Int64()" \
// RUN: | %target-swift-frontend -module-name FooBar -emit-module -o %t -
// RUN: %target-swift-frontend %s -O -I %t -emit-ir -g -o %t.ll
// RUN: FileCheck %s < %t.ll
// RUN: FileCheck %s -check-prefix=TRANSPARENT-CHECK < %t.ll

// CHECK: define{{( protected)?( signext)?}} i32 @main
// CHECK: tail call { i64, i1 } @llvm.smul.with.overflow.i64(i64 %[[C:.*]], i64 %[[C]]), !dbg ![[MULSCOPE:.*]]
// CHECK: call {{.*}}noinline{{.*}}, !dbg ![[CALL:.*]]
// CHECK-DAG: ![[TOPLEVEL:.*]] = !DIFile(filename: "inlinescopes.swift"

import FooBar

func markUsed<T>(_ t: T) {}
func use<T>(_ t: T) {}

@inline(never)
func noinline(_ x: Int64) -> Int64 { return x }

@_transparent
func transparent(_ x: Int64) -> Int64 { return noinline(x) }


@inline(__always)
func square(_ x: Int64) -> Int64 {
// CHECK-DAG: ![[MULSCOPE]] = !DILocation(line: [[@LINE+2]], column: {{.*}}, scope: ![[MUL:.*]], inlinedAt: ![[INLINED:.*]])
// CHECK-DAG: ![[MUL:.*]] = distinct !DILexicalBlock(
let res = x * x
// *(Int, Int) is a transparent function and should not show up in the debug info.
// TRANSPARENT-CHECK-NOT: !DISubprogram(name: "_TFsoi1mFTSiSi_Si"
return res
func inlined(_ x: Int64) -> Int64 {
// CHECK-DAG: ![[CALL]] = !DILocation(line: [[@LINE+2]], column: {{.*}}, scope: ![[SCOPE:.*]], inlinedAt: ![[INLINED:.*]])
// CHECK-DAG: ![[SCOPE:.*]] = distinct !DILexicalBlock(
let result = transparent(x)
// TRANSPARENT-CHECK-NOT: !DISubprogram(name: "transparent"
return result
}
let c = Int64(x)
// CHECK-DAG: !DIGlobalVariable(name: "y",{{.*}} file: ![[TOPLEVEL]],{{.*}} line: [[@LINE+1]]
let y = square(c)
markUsed(y)
let y = inlined(x)
use(y)

// Check if the inlined and removed square function still has the correct linkage name in the debug info.
// CHECK-DAG: !DISubprogram(name: "square", linkageName: "_TF4main6squareFVs5Int64S0_"
// Check if the inlined and removed function still has the correct linkage name.
// CHECK-DAG: !DISubprogram(name: "inlined", linkageName: "_TF4main7inlinedFVs5Int64S0_"
33 changes: 23 additions & 10 deletions test/DebugInfo/specialization.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
// RUN: %target-swift-frontend -O %s -disable-llvm-optzns -emit-sil -g -o - | FileCheck %s

// CHECK: sil shared [noinline] @_TTSg5SiSis17IntegerArithmetics__
// CHECK-SAME: _TF14specialization3sumuRxs17IntegerArithmeticrFTxx_x
// CHECK-SAME: $@convention(thin) (Int, Int) -> Int {
// CHECK: bb0(%0 : $Int, %1 : $Int):
// CHECK: debug_value %0 : $Int, let, name "i", argno 1
// CHECK: debug_value %1 : $Int, let, name "j", argno 2

// CHECK: sil shared [noinline] @_TTSg5V14specialization7AddableS0_S_5ProtoS____TF14specialization3sumuRxS_5ProtorFTxx_x
// CHECK-SAME: $@convention(thin) (Addable, Addable) -> Addable {
// CHECK: bb0(%0 : $Addable, %1 : $Addable):
// CHECK: debug_value %0 : $Addable, let, name "i", argno 1
// CHECK: debug_value %1 : $Addable, let, name "j", argno 2

public protocol Proto {
static func +(lhs: Self, rhs: Self) -> Self
}

@inline(never)
public func sum<T : IntegerArithmetic>(_ i : T, _ j : T) -> T {
public func sum<T : Proto>(_ i : T, _ j : T) -> T {
let result = i + j
return result
}

public func inc(_ i: inout Int) {
i = sum(i, 1)
func add(_ x: Int, _ y: Int) -> Int { return x+y }
public struct Addable : Proto {
let val : Int
init(_ i : Int) { val = i }
public static func +(lhs: Addable, rhs: Addable) -> Addable {
return Addable(add(lhs.val, rhs.val))
}
}


public func inc(_ i: inout Addable) {
i = sum(i, Addable(1))
}