• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #define BITS(T)		(sizeof(T) * 8)
2 #define SIGN_BIT(T)	(1ULL << (BITS(T) - 1))
3 #define SMASK(T)	(SIGN_BIT(T) - 1)
4 #define UMASK(T)	(SIGN_BIT(T) | SMASK(T))
5 
6 int test(void);
test(void)7 int test(void)
8 {
9 #define TEST_BIT(X, T)	if (__ ## X ## _BIT__  != BITS(T)) return 1
10 	TEST_BIT(CHAR, char);
11 
12 #define TEST_MAX(X, M)	if (__ ## X ## _MAX__ != M) return 1
13 #define TEST_SMAX(X, T)	TEST_MAX(X, SMASK(T))
14 #define TEST_UMAX(X, T)	TEST_MAX(X, UMASK(T))
15 	TEST_SMAX(SCHAR, signed char);
16 	TEST_SMAX(SHRT, short);
17 	TEST_SMAX(INT, int);
18 	TEST_SMAX(LONG, long);
19 	TEST_SMAX(LONG_LONG, long long);
20 	TEST_MAX( INT8,  0x7f);
21 	TEST_MAX(UINT8,  0xffU);
22 	TEST_MAX( INT16, 0x7fff);
23 	TEST_MAX(UINT16, 0xffffU);
24 	TEST_MAX( INT32, 0x7fffffff);
25 	TEST_MAX(UINT32, 0xffffffffU);
26 	TEST_MAX( INT64, 0x7fffffffffffffffLL);
27 	TEST_MAX(UINT64, 0xffffffffffffffffULL);
28 	TEST_SMAX(INTMAX, __INTMAX_TYPE__);
29 	TEST_UMAX(UINTMAX, __UINTMAX_TYPE__);
30 	TEST_SMAX(INTPTR, __INTPTR_TYPE__);
31 	TEST_UMAX(UINTPTR, __UINTPTR_TYPE__);
32 	TEST_SMAX(PTRDIFF, __PTRDIFF_TYPE__);
33 	TEST_UMAX(SIZE, __SIZE_TYPE__);
34 
35 #define TEST_SIZEOF(X, T) if (__SIZEOF_ ## X ## __ != sizeof(T)) return 1
36 	TEST_SIZEOF(SHORT, short);
37 	TEST_SIZEOF(INT, int);
38 	TEST_SIZEOF(LONG, long);
39 	TEST_SIZEOF(LONG_LONG, long long);
40 #ifdef __SIZEOF_INT128__
41 	TEST_SIZEOF(INT128, __int128);
42 #endif
43 	TEST_SIZEOF(PTRDIFF_T, __PTRDIFF_TYPE__);
44 	TEST_SIZEOF(SIZE_T, __SIZE_TYPE__);
45 	TEST_SIZEOF(POINTER, void*);
46 	TEST_SIZEOF(FLOAT, float);
47 	TEST_SIZEOF(DOUBLE, double);
48 	TEST_SIZEOF(LONG_DOUBLE, long double);
49 
50 	return 0;
51 }
52 
53 /*
54  * check-name: predefined macros: __SIZEOF_<type>__, ...
55  * check-command: test-linearize -Wno-decl $file
56  * check-output-ignore
57  *
58  * check-output-contains: ret\\..*\\$0
59  */
60