Skip to content

Commit 2127af8

Browse files
[compiler-rt][ubsa] Reformat cast-overflow test. NFC (#129662)
Reformat cast-overflow test. NFC
1 parent 9084d2a commit 2127af8

File tree

1 file changed

+39
-40
lines changed

1 file changed

+39
-40
lines changed

compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,41 @@
1515
// This test assumes float and double are IEEE-754 single- and double-precision.
1616

1717
#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
2222
#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
3333
#elif defined(__sun__) && defined(__svr4__)
3434
// 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
4343
#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
4747
#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__
5353
#include <stdint.h>
5454
#include <stdio.h>
5555
#include <string.h>
@@ -59,7 +59,7 @@ float NaN;
5959

6060
int main(int argc, char **argv) {
6161
float MaxFloatRepresentableAsInt = 0x7fffff80;
62-
(int)MaxFloatRepresentableAsInt; // ok
62+
(int)MaxFloatRepresentableAsInt; // ok
6363
(int)-MaxFloatRepresentableAsInt; // ok
6464

6565
float MinFloatRepresentableAsInt = -0x7fffffff - 1;
@@ -78,18 +78,18 @@ int main(int argc, char **argv) {
7878

7979
// Build a '+Inf'.
8080
#if BYTE_ORDER == LITTLE_ENDIAN
81-
unsigned char InfVal[] = { 0x00, 0x00, 0x80, 0x7f };
81+
unsigned char InfVal[] = {0x00, 0x00, 0x80, 0x7f};
8282
#else
83-
unsigned char InfVal[] = { 0x7f, 0x80, 0x00, 0x00 };
83+
unsigned char InfVal[] = {0x7f, 0x80, 0x00, 0x00};
8484
#endif
8585
float Inf;
8686
memcpy(&Inf, InfVal, 4);
8787

8888
// Build a 'NaN'.
8989
#if BYTE_ORDER == LITTLE_ENDIAN
90-
unsigned char NaNVal[] = { 0x01, 0x00, 0x80, 0x7f };
90+
unsigned char NaNVal[] = {0x01, 0x00, 0x80, 0x7f};
9191
#else
92-
unsigned char NaNVal[] = { 0x7f, 0x80, 0x00, 0x01 };
92+
unsigned char NaNVal[] = {0x7f, 0x80, 0x00, 0x01};
9393
#endif
9494
float NaN;
9595
memcpy(&NaN, NaNVal, 4);
@@ -107,7 +107,7 @@ int main(int argc, char **argv) {
107107
static int test_int = MaxFloatRepresentableAsInt + 0x80;
108108
// CHECK-0: SUMMARY: {{.*}}Sanitizer: float-cast-overflow {{.*}}cast-overflow.cpp:[[@LINE-1]]
109109
return 0;
110-
}
110+
}
111111
case '1': {
112112
// CHECK-1: {{.*}}cast-overflow.cpp:[[@LINE+1]]:27: runtime error: -2.14748{{.*}} is outside the range of representable values of type 'int'
113113
static int test_int = MinFloatRepresentableAsInt - 0x100;
@@ -135,16 +135,15 @@ int main(int argc, char **argv) {
135135
static int test_int = NaN;
136136
return 0;
137137
}
138-
139-
// Integer -> floating point overflow.
138+
// Integer -> floating point overflow.
140139
case '6': {
141140
// 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}}
142141
#if defined(__SIZEOF_INT128__) && !defined(_WIN32)
143142
static int test_int = (float)(FloatMaxAsUInt128 + 1);
144143
return 0;
145144
#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
148147
printf("%s:%d: __int128 not supported", __FILE__, __LINE__ - 5);
149148
return 0;
150149
#endif

0 commit comments

Comments
 (0)