|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %build-irgen-test-overlays |
| 3 | +// RUN: %target-swift-frontend -sdk %S/Inputs -primary-file %s -trap-function oopsie -enable-objc-interop -emit-ir -module-name trap_function -I %t | %FileCheck %s -check-prefix=TRAPFN |
| 4 | +// RUN: %target-swift-frontend -O -sdk %S/Inputs -primary-file %s -trap-function oopsie -enable-objc-interop -emit-ir -module-name trap_function -I %t | %FileCheck %s -check-prefix=TRAPFN_OPT |
| 5 | +// RUN: %target-swift-frontend -sdk %S/Inputs -primary-file %s -enable-objc-interop -emit-ir -module-name trap_function -I %t | %FileCheck %s -check-prefix=NOTRAPFN |
| 6 | + |
| 7 | +import gizmo |
| 8 | + |
| 9 | +// TRAPFN-LABEL: define hidden swiftcc {{.*}} @"$s13trap_function14checkOverflow1yS2i_SitF" |
| 10 | +// TRAPFN: call void @llvm.trap() [[ATTR0:#[0-9]+]] |
| 11 | + |
| 12 | +// TRAPFN_OPT-LABEL: define hidden swiftcc {{.*}} @"$s13trap_function14checkOverflow1yS2i_SitF" |
| 13 | +// TRAPFN_OPT: call void @llvm.trap() [[ATTR0:#[0-9]+]] |
| 14 | + |
| 15 | +// NOTRAPFN-LABEL: define hidden swiftcc {{.*}} @"$s13trap_function14checkOverflow1yS2i_SitF" |
| 16 | +// NOTRAPFN: call void @llvm.trap(){{$}} |
| 17 | +func checkOverflow1(_ a: Int, _ b: Int) -> Int { |
| 18 | + a + b |
| 19 | +} |
| 20 | + |
| 21 | +// TRAPFN-LABEL: define hidden swiftcc {{.*}} @"$s13trap_function14checkOverflow2yySiz_SitF" |
| 22 | +// TRAPFN: call void @llvm.trap() [[ATTR0:#[0-9]+]] |
| 23 | + |
| 24 | +// TRAPFN_OPT-LABEL: define hidden swiftcc {{.*}} @"$s13trap_function14checkOverflow2yySiz_SitF" |
| 25 | +// TRAPFN_OPT: call void @llvm.trap() [[ATTR0:#[0-9]+]] |
| 26 | + |
| 27 | +// NOTRAPFN-LABEL: define hidden swiftcc {{.*}} @"$s13trap_function14checkOverflow2yySiz_SitF" |
| 28 | +// NOTRAPFN: call void @llvm.trap(){{$}} |
| 29 | +func checkOverflow2(_ a: inout Int, _ b: Int) { |
| 30 | + a *= b |
| 31 | +} |
| 32 | + |
| 33 | +// TRAPFN-LABEL: define hidden swiftcc void @"$s13trap_function17checkPreconditionyySiF" |
| 34 | +// TRAPFN: call swiftcc void @"$ss17_assertionFailure__4file4line5flagss5NeverOs12StaticStringV_SSAHSus6UInt32VtF" |
| 35 | +// TRAPFN-NOT: call void @llvm.trap() |
| 36 | + |
| 37 | +// TRAPFN_OPT-LABEL: define hidden swiftcc void @"$s13trap_function17checkPreconditionyySiF" |
| 38 | +// TRAPFN_OPT: call void @llvm.trap() [[ATTR0]] |
| 39 | + |
| 40 | +// NOTRAPFN-LABEL: define hidden swiftcc void @"$s13trap_function17checkPreconditionyySiF" |
| 41 | +// NOTRAPFN: call swiftcc void @"$ss17_assertionFailure__4file4line5flagss5NeverOs12StaticStringV_SSAHSus6UInt32VtF" |
| 42 | +func checkPrecondition(_ a: Int) { |
| 43 | + precondition(a != 23) |
| 44 | +} |
| 45 | + |
| 46 | +// TRAPFN-LABEL: define hidden swiftcc void @"$s13trap_function24checkPreconditionFailureyySiF" |
| 47 | +// TRAPFN: call swiftcc void @"$ss17_assertionFailure__4file4line5flagss5NeverOs12StaticStringV_SSAHSus6UInt32VtF" |
| 48 | +// TRAPFN-NOT: call void @llvm.trap() |
| 49 | + |
| 50 | +// TRAPFN_OPT-LABEL: define hidden swiftcc void @"$s13trap_function24checkPreconditionFailureyySiF" |
| 51 | +// TRAPFN_OPT: call void @llvm.trap() [[ATTR0]] |
| 52 | + |
| 53 | +// NOTRAPFN-LABEL: define hidden swiftcc void @"$s13trap_function24checkPreconditionFailureyySiF" |
| 54 | +// NOTRAPFN: call swiftcc void @"$ss17_assertionFailure__4file4line5flagss5NeverOs12StaticStringV_SSAHSus6UInt32VtF" |
| 55 | +func checkPreconditionFailure(_ a: Int) { |
| 56 | + if a == 42 { |
| 57 | + preconditionFailure() |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +// TRAPFN-LABEL: define hidden swiftcc void @"$s13trap_function18checkClangImporteryyF" |
| 62 | +// TRAPFN: call {{.*}} @ackbar() |
| 63 | + |
| 64 | +// TRAPFN_OPT-LABEL: define hidden swiftcc void @"$s13trap_function18checkClangImporteryyF" |
| 65 | +// TRAPFN_OPT: call {{.*}} @ackbar() |
| 66 | + |
| 67 | +// NOTRAPFN-LABEL: define hidden swiftcc void @"$s13trap_function18checkClangImporteryyF" |
| 68 | +// NOTRAPFN: call {{.*}} @ackbar() |
| 69 | +func checkClangImporter() { |
| 70 | + ackbar() |
| 71 | +} |
| 72 | + |
| 73 | +// TRAPFN-LABEL: define internal {{.*}} @ackbar() |
| 74 | +// TRAPFN: call void @llvm.trap() [[ATTR0]] |
| 75 | + |
| 76 | +// TRAPFN_OPT-LABEL: define internal {{.*}} @ackbar() |
| 77 | +// TRAPFN_OPT: call void @llvm.trap() [[ATTR0]] |
| 78 | + |
| 79 | +// NOTRAPFN-LABEL: define internal {{.*}} @ackbar() |
| 80 | +// NOTRAPFN: call void @llvm.trap(){{$}} |
| 81 | + |
| 82 | + |
| 83 | +// TRAPFN: attributes [[ATTR0]] = { {{.*}}"trap-func-name"="oopsie" } |
| 84 | +// NOTRAPFN-NOT: attributes {{.*}} = { {{.*}}"trap-func-name"="oopsie" } |
0 commit comments