1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
// The tester will only work when asserts file
// REQUIRES: asserts
// We put in a bunch of checks since we are making platform specific assumptions
// about putchar, so we are being paranoid.
// REQUIRES: OS=macosx
// REQUIRES: CPU=x86_64
// REQUIRES: PTRSIZE=64
// Clear the temporary directory
// RUN: %empty-directory(%t)
// We use a driver file to ensure that we are not dependent on how main/start
// are setup on our platform. The c function interface that we use is very
// standard, so we should be ok to rely on it. Lets compile it.
// RUN: %target-swift-frontend -c %S/Inputs/bug-reducer-tester-miscompile-driver.swift -o %t/main.o
// Now test the base case. We emit a sib file/etc to make sure all of the
// components of our test work, even though we could just use a sil file
// directly.
// RUN: %target-sil-opt %s -emit-sib -o %t/good.sib -module-name main
// RUN: %target-swift-frontend -c %t/good.sib -o %t/good.o -module-name main
// RUN: %target-swiftc_driver -o %t/good %t/good.o %t/main.o -module-name main
// RUN: %t/good | %FileCheck %s
// Now try to insert a runtime crash and make sure that we hit the crash.
// RUN: %target-sil-opt -bug-reducer-tester %s -bug-reducer-tester-failure-kind=runtime-crasher -bug-reducer-tester-target-func='target_func' -emit-sib -o %t/runtime_crasher.sib -module-name main
// RUN: %target-swift-frontend -c %t/runtime_crasher.sib -o %t/runtime_crasher.o -module-name main
// RUN: %target-swiftc_driver -o %t/runtime_crasher %t/runtime_crasher.o %t/main.o -module-name main
// RUN: not --crash %t/runtime_crasher
// CHECK: swift
// CHECK: swift
// CHECK: swift
sil_stage canonical
import Builtin
sil @putchar : $@convention(c) (Builtin.Int64) -> ()
sil [serialized] @target_func : $@convention(thin) () -> () {
bb0:
%0 = function_ref @putchar : $@convention(c) (Builtin.Int64) -> ()
// "swift\n" in ASCII
%1 = integer_literal $Builtin.Int64, 115
%2 = integer_literal $Builtin.Int64, 119
%3 = integer_literal $Builtin.Int64, 105
%4 = integer_literal $Builtin.Int64, 102
%5 = integer_literal $Builtin.Int64, 116
%6 = integer_literal $Builtin.Int64, 10
apply %0(%1) : $@convention(c) (Builtin.Int64) -> ()
apply %0(%2) : $@convention(c) (Builtin.Int64) -> ()
apply %0(%3) : $@convention(c) (Builtin.Int64) -> ()
apply %0(%4) : $@convention(c) (Builtin.Int64) -> ()
apply %0(%5) : $@convention(c) (Builtin.Int64) -> ()
apply %0(%6) : $@convention(c) (Builtin.Int64) -> ()
%9999 = tuple()
return %9999 : $()
}
sil [serialized] @function_2 : $@convention(thin) () -> () {
bb0:
%0 = function_ref @target_func : $@convention(thin) () -> ()
apply %0() : $@convention(thin) () -> ()
// Make sure we only eliminate one.
apply %0() : $@convention(thin) () -> ()
%1 = function_ref @function_3 : $@convention(thin) () -> ()
apply %1() : $@convention(thin) () -> ()
%9999 = tuple()
return %9999 : $()
}
sil [serialized] @function_3 : $@convention(thin) () -> () {
bb0:
// Make sure we only eliminate one.
%0 = function_ref @target_func : $@convention(thin) () -> ()
apply %0() : $@convention(thin) () -> ()
%9999 = tuple()
return %9999 : $()
}
|