15
15
// This test assumes float and double are IEEE-754 single- and double-precision.
16
16
17
17
#if defined(__APPLE__)
18
- # include < machine/endian.h>
19
- # define BYTE_ORDER __DARWIN_BYTE_ORDER
20
- # define BIG_ENDIAN __DARWIN_BIG_ENDIAN
21
- # define LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
18
+ # include < machine/endian.h>
19
+ # define BYTE_ORDER __DARWIN_BYTE_ORDER
20
+ # define BIG_ENDIAN __DARWIN_BIG_ENDIAN
21
+ # define LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
22
22
#elif defined(__FreeBSD__) || defined(__NetBSD__)
23
- # include < sys/endian.h>
24
- # ifndef BYTE_ORDER
25
- # define BYTE_ORDER _BYTE_ORDER
26
- # endif
27
- # ifndef BIG_ENDIAN
28
- # define BIG_ENDIAN _BIG_ENDIAN
29
- # endif
30
- # ifndef LITTLE_ENDIAN
31
- # define LITTLE_ENDIAN _LITTLE_ENDIAN
32
- # endif
23
+ # include < sys/endian.h>
24
+ # ifndef BYTE_ORDER
25
+ # define BYTE_ORDER _BYTE_ORDER
26
+ # endif
27
+ # ifndef BIG_ENDIAN
28
+ # define BIG_ENDIAN _BIG_ENDIAN
29
+ # endif
30
+ # ifndef LITTLE_ENDIAN
31
+ # define LITTLE_ENDIAN _LITTLE_ENDIAN
32
+ # endif
33
33
#elif defined(__sun__) && defined(__svr4__)
34
34
// Solaris provides _BIG_ENDIAN/_LITTLE_ENDIAN selector in sys/types.h.
35
- # include < sys/types.h>
36
- # define BIG_ENDIAN 4321
37
- # define LITTLE_ENDIAN 1234
38
- # if defined(_BIG_ENDIAN)
39
- # define BYTE_ORDER BIG_ENDIAN
40
- # else
41
- # define BYTE_ORDER LITTLE_ENDIAN
42
- # endif
35
+ # include < sys/types.h>
36
+ # define BIG_ENDIAN 4321
37
+ # define LITTLE_ENDIAN 1234
38
+ # if defined(_BIG_ENDIAN)
39
+ # define BYTE_ORDER BIG_ENDIAN
40
+ # else
41
+ # define BYTE_ORDER LITTLE_ENDIAN
42
+ # endif
43
43
#elif defined(_WIN32)
44
- # define BYTE_ORDER 0
45
- # define BIG_ENDIAN 1
46
- # define LITTLE_ENDIAN 0
44
+ # define BYTE_ORDER 0
45
+ # define BIG_ENDIAN 1
46
+ # define LITTLE_ENDIAN 0
47
47
#else
48
- # include < endian.h>
49
- # define BYTE_ORDER __BYTE_ORDER
50
- # define BIG_ENDIAN __BIG_ENDIAN
51
- # define LITTLE_ENDIAN __LITTLE_ENDIAN
52
- #endif // __APPLE__
48
+ # include < endian.h>
49
+ # define BYTE_ORDER __BYTE_ORDER
50
+ # define BIG_ENDIAN __BIG_ENDIAN
51
+ # define LITTLE_ENDIAN __LITTLE_ENDIAN
52
+ #endif // __APPLE__
53
53
#include < stdint.h>
54
54
#include < stdio.h>
55
55
#include < string.h>
@@ -59,7 +59,7 @@ float NaN;
59
59
60
60
int main (int argc, char **argv) {
61
61
float MaxFloatRepresentableAsInt = 0x7fffff80 ;
62
- (int )MaxFloatRepresentableAsInt; // ok
62
+ (int )MaxFloatRepresentableAsInt; // ok
63
63
(int )-MaxFloatRepresentableAsInt; // ok
64
64
65
65
float MinFloatRepresentableAsInt = -0x7fffffff - 1 ;
@@ -78,18 +78,18 @@ int main(int argc, char **argv) {
78
78
79
79
// Build a '+Inf'.
80
80
#if BYTE_ORDER == LITTLE_ENDIAN
81
- unsigned char InfVal[] = { 0x00 , 0x00 , 0x80 , 0x7f };
81
+ unsigned char InfVal[] = {0x00 , 0x00 , 0x80 , 0x7f };
82
82
#else
83
- unsigned char InfVal[] = { 0x7f , 0x80 , 0x00 , 0x00 };
83
+ unsigned char InfVal[] = {0x7f , 0x80 , 0x00 , 0x00 };
84
84
#endif
85
85
float Inf;
86
86
memcpy (&Inf, InfVal, 4 );
87
87
88
88
// Build a 'NaN'.
89
89
#if BYTE_ORDER == LITTLE_ENDIAN
90
- unsigned char NaNVal[] = { 0x01 , 0x00 , 0x80 , 0x7f };
90
+ unsigned char NaNVal[] = {0x01 , 0x00 , 0x80 , 0x7f };
91
91
#else
92
- unsigned char NaNVal[] = { 0x7f , 0x80 , 0x00 , 0x01 };
92
+ unsigned char NaNVal[] = {0x7f , 0x80 , 0x00 , 0x01 };
93
93
#endif
94
94
float NaN;
95
95
memcpy (&NaN, NaNVal, 4 );
@@ -107,7 +107,7 @@ int main(int argc, char **argv) {
107
107
static int test_int = MaxFloatRepresentableAsInt + 0x80 ;
108
108
// CHECK-0: SUMMARY: {{.*}}Sanitizer: float-cast-overflow {{.*}}cast-overflow.cpp:[[@LINE-1]]
109
109
return 0 ;
110
- }
110
+ }
111
111
case ' 1' : {
112
112
// CHECK-1: {{.*}}cast-overflow.cpp:[[@LINE+1]]:27: runtime error: -2.14748{{.*}} is outside the range of representable values of type 'int'
113
113
static int test_int = MinFloatRepresentableAsInt - 0x100 ;
@@ -135,16 +135,15 @@ int main(int argc, char **argv) {
135
135
static int test_int = NaN;
136
136
return 0 ;
137
137
}
138
-
139
- // Integer -> floating point overflow.
138
+ // Integer -> floating point overflow.
140
139
case ' 6' : {
141
140
// CHECK-6: cast-overflow.cpp:[[@LINE+2]]:{{27: runtime error: 3.40282e\+38 is outside the range of representable values of type 'int'| __int128 not supported}}
142
141
#if defined(__SIZEOF_INT128__) && !defined(_WIN32)
143
142
static int test_int = (float )(FloatMaxAsUInt128 + 1 );
144
143
return 0 ;
145
144
#else
146
- // Print the same line as the check above. That way the test is robust to
147
- // line changes around it
145
+ // Print the same line as the check above.
146
+ // That way the test is robust to line changes around it
148
147
printf (" %s:%d: __int128 not supported" , __FILE__, __LINE__ - 5 );
149
148
return 0 ;
150
149
#endif
0 commit comments