-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathFloatingPointConversionTraps.swift.gyb
131 lines (105 loc) · 3.54 KB
/
FloatingPointConversionTraps.swift.gyb
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: %S/../../utils/gyb %s -o %t/FloatingPointConversionTraps.swift
// RUN: %S/../../utils/line-directive %t/FloatingPointConversionTraps.swift -- %target-build-swift %t/FloatingPointConversionTraps.swift -Xfrontend -disable-access-control -o %t/a.out_Debug
// RUN: %S/../../utils/line-directive %t/FloatingPointConversionTraps.swift -- %target-build-swift %t/FloatingPointConversionTraps.swift -Xfrontend -disable-access-control -o %t/a.out_Release -O
//
// RUN: %S/../../utils/line-directive %t/FloatingPointConversionTraps.swift -- %target-run %t/a.out_Debug
// RUN: %S/../../utils/line-directive %t/FloatingPointConversionTraps.swift -- %target-run %t/a.out_Release
// REQUIRES: executable_test
import StdlibUnittest
%{
from SwiftIntTypes import *
# Test cases are written in a way that they don't depend on the word size.
word_bits = 4
}%
#if arch(i386) || arch(x86_64)
extension Float80 {
public static var infinity: Float80 {
return 1.0 / 0.0
}
public static var quietNaN: Float80 {
return 0.0 / 0.0
}
}
#endif
func getInfiniteOrNaNMessage(floatType: String) -> String {
// FIXME: <rdar://problem/17958458> Int(Float80.quietNaN) is garbage
if floatType == "Float80" {
return ""
}
if _isDebugAssertConfiguration() {
return "either infinite or NaN"
}
return ""
}
func getTooSmallMessage() -> String {
if _isDebugAssertConfiguration() {
return "it is less than"
}
return ""
}
func getTooLargeMessage() -> String {
if _isDebugAssertConfiguration() {
return "it is greater than"
}
return ""
}
var FloatingPointConversion = TestSuite("FloatingPointConversion")
% for FloatSelf in ['Float32', 'Float64', 'Float80']:
% for int_ty in all_integer_types(word_bits):
% IntSelf = int_ty.stdlib_name
% if FloatSelf == 'Float80':
#if arch(i386) || arch(x86_64)
% end
FloatingPointConversion.test("${FloatSelf}/${IntSelf}/+inf")
.crashOutputMatches(getInfiniteOrNaNMessage("${FloatSelf}")).code {
if true {
var a = get${IntSelf}(${IntSelf}(get${FloatSelf}(0.0)))
expectEqual(0, a)
}
if true {
var a = get${IntSelf}(${IntSelf}(get${FloatSelf}(123.0)))
expectEqual(123, a)
}
expectCrashLater()
get${IntSelf}(${IntSelf}(get${FloatSelf}(+${FloatSelf}.infinity)))
}
% if int_ty.is_signed:
FloatingPointConversion.test("${FloatSelf}/${IntSelf}/-inf")
.crashOutputMatches(getInfiniteOrNaNMessage("${FloatSelf}")).code {
if true {
var a = get${IntSelf}(${IntSelf}(get${FloatSelf}(-0.0)))
expectEqual(0, a)
}
if true {
var a = get${IntSelf}(${IntSelf}(get${FloatSelf}(-123.0)))
expectEqual(-123, a)
}
expectCrashLater()
get${IntSelf}(${IntSelf}(get${FloatSelf}(-${FloatSelf}.infinity)))
}
% else:
FloatingPointConversion.test("${FloatSelf}/${IntSelf}/negative")
.crashOutputMatches(getTooSmallMessage()).code {
expectCrashLater()
get${IntSelf}(${IntSelf}(get${FloatSelf}(-123.0)))
}
FloatingPointConversion.test("${FloatSelf}/${IntSelf}/-inf")
.crashOutputMatches(getInfiniteOrNaNMessage("${FloatSelf}")).code {
expectCrashLater()
get${IntSelf}(${IntSelf}(get${FloatSelf}(-${FloatSelf}.infinity)))
}
% end
FloatingPointConversion.test("${FloatSelf}/${IntSelf}/NaN")
.xfail(.Custom({ "${FloatSelf}" == "Float80" }, reason: "<rdar://problem/17958458> Int(Float80.quietNaN) is garbage"))
.crashOutputMatches(getInfiniteOrNaNMessage("${FloatSelf}")).code {
expectCrashLater()
get${IntSelf}(${IntSelf}(get${FloatSelf}(${FloatSelf}.quietNaN)))
}
% if FloatSelf == 'Float80':
#endif
% end
% end
% end
runAllTests()