Skip to content

Commit 2be0115

Browse files
[clang][headers] Need a way for math.h to share the definitions of INIFINITY and NAN with float.h
In C23 mode, both float.h and math.h are required to define INIFINITY and NAN. However, with clang modules, there needs to be a single owner for the declarations. Let that be float.h since that's the compiler header, and introduce `__need_infinity_nan` so that math.h can pick up the compiler definitions.
1 parent ac65da0 commit 2be0115

File tree

10 files changed

+293
-166
lines changed

10 files changed

+293
-166
lines changed

clang-tools-extra/clang-include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ namespace find_all_symbols {
1313

1414
const HeaderMapCollector::RegexHeaderMap *getSTLPostfixHeaderMap() {
1515
static const HeaderMapCollector::RegexHeaderMap STLPostfixHeaderMap = {
16+
{"include/__float_float.h$", "<cfloat>"},
17+
{"include/__float_header_macro.h$", "<cfloat>"},
18+
{"include/__float_infinity_nan.h$", "<cfloat>"},
1619
{"include/__stdarg___gnuc_va_list.h$", "<cstdarg>"},
1720
{"include/__stdarg___va_copy.h$", "<cstdarg>"},
1821
{"include/__stdarg_header_macro.h$", "<cstdarg>"},

clang-tools-extra/clangd/index/CanonicalIncludes.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ namespace clang {
1616
namespace clangd {
1717
namespace {
1818
const std::pair<llvm::StringRef, llvm::StringRef> IncludeMappings[] = {
19+
{"include/__float_float.h", "<cfloat>"},
20+
{"include/__float_header_macro.h", "<cfloat>"},
21+
{"include/__float_infinity_nan.h", "<cfloat>"},
1922
{"include/__stdarg___gnuc_va_list.h", "<cstdarg>"},
2023
{"include/__stdarg___va_copy.h", "<cstdarg>"},
2124
{"include/__stdarg_header_macro.h", "<cstdarg>"},

clang/lib/Headers/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
set(core_files
55
builtins.h
66
float.h
7+
__float_float.h
8+
__float_header_macro.h
9+
__float_infinity_nan.h
710
inttypes.h
811
iso646.h
912
limits.h

clang/lib/Headers/__float_float.h

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
/*===---- __float_float.h --------------------------------------------------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*/
9+
10+
#ifndef __CLANG_FLOAT_FLOAT_H
11+
#define __CLANG_FLOAT_FLOAT_H
12+
13+
#if (defined(__MINGW32__) || defined(_MSC_VER) || defined(_AIX)) && \
14+
__STDC_HOSTED__
15+
16+
/* Undefine anything that we'll be redefining below. */
17+
# undef FLT_EVAL_METHOD
18+
# undef FLT_ROUNDS
19+
# undef FLT_RADIX
20+
# undef FLT_MANT_DIG
21+
# undef DBL_MANT_DIG
22+
# undef LDBL_MANT_DIG
23+
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
24+
!defined(__STRICT_ANSI__) || \
25+
(defined(__cplusplus) && __cplusplus >= 201103L) || \
26+
(__STDC_HOSTED__ && defined(_AIX) && defined(_ALL_SOURCE))
27+
# undef DECIMAL_DIG
28+
# endif
29+
# undef FLT_DIG
30+
# undef DBL_DIG
31+
# undef LDBL_DIG
32+
# undef FLT_MIN_EXP
33+
# undef DBL_MIN_EXP
34+
# undef LDBL_MIN_EXP
35+
# undef FLT_MIN_10_EXP
36+
# undef DBL_MIN_10_EXP
37+
# undef LDBL_MIN_10_EXP
38+
# undef FLT_MAX_EXP
39+
# undef DBL_MAX_EXP
40+
# undef LDBL_MAX_EXP
41+
# undef FLT_MAX_10_EXP
42+
# undef DBL_MAX_10_EXP
43+
# undef LDBL_MAX_10_EXP
44+
# undef FLT_MAX
45+
# undef DBL_MAX
46+
# undef LDBL_MAX
47+
# undef FLT_EPSILON
48+
# undef DBL_EPSILON
49+
# undef LDBL_EPSILON
50+
# undef FLT_MIN
51+
# undef DBL_MIN
52+
# undef LDBL_MIN
53+
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
54+
!defined(__STRICT_ANSI__) || \
55+
(defined(__cplusplus) && __cplusplus >= 201703L) || \
56+
(__STDC_HOSTED__ && defined(_AIX) && defined(_ALL_SOURCE))
57+
# undef FLT_TRUE_MIN
58+
# undef DBL_TRUE_MIN
59+
# undef LDBL_TRUE_MIN
60+
# undef FLT_DECIMAL_DIG
61+
# undef DBL_DECIMAL_DIG
62+
# undef LDBL_DECIMAL_DIG
63+
# undef FLT_HAS_SUBNORM
64+
# undef DBL_HAS_SUBNORM
65+
# undef LDBL_HAS_SUBNORM
66+
# endif
67+
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || \
68+
!defined(__STRICT_ANSI__)
69+
# undef FLT_NORM_MAX
70+
# undef DBL_NORM_MAX
71+
# undef LDBL_NORM_MAX
72+
#endif
73+
#endif
74+
75+
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || \
76+
!defined(__STRICT_ANSI__)
77+
# undef FLT_SNAN
78+
# undef DBL_SNAN
79+
# undef LDBL_SNAN
80+
#endif
81+
82+
/* Characteristics of floating point types, C99 5.2.4.2.2 */
83+
84+
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
85+
(defined(__cplusplus) && __cplusplus >= 201103L)
86+
#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
87+
#endif
88+
#define FLT_ROUNDS (__builtin_flt_rounds())
89+
#define FLT_RADIX __FLT_RADIX__
90+
91+
#define FLT_MANT_DIG __FLT_MANT_DIG__
92+
#define DBL_MANT_DIG __DBL_MANT_DIG__
93+
#define LDBL_MANT_DIG __LDBL_MANT_DIG__
94+
95+
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
96+
!defined(__STRICT_ANSI__) || \
97+
(defined(__cplusplus) && __cplusplus >= 201103L) || \
98+
(__STDC_HOSTED__ && defined(_AIX) && defined(_ALL_SOURCE))
99+
# define DECIMAL_DIG __DECIMAL_DIG__
100+
#endif
101+
102+
#define FLT_DIG __FLT_DIG__
103+
#define DBL_DIG __DBL_DIG__
104+
#define LDBL_DIG __LDBL_DIG__
105+
106+
#define FLT_MIN_EXP __FLT_MIN_EXP__
107+
#define DBL_MIN_EXP __DBL_MIN_EXP__
108+
#define LDBL_MIN_EXP __LDBL_MIN_EXP__
109+
110+
#define FLT_MIN_10_EXP __FLT_MIN_10_EXP__
111+
#define DBL_MIN_10_EXP __DBL_MIN_10_EXP__
112+
#define LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__
113+
114+
#define FLT_MAX_EXP __FLT_MAX_EXP__
115+
#define DBL_MAX_EXP __DBL_MAX_EXP__
116+
#define LDBL_MAX_EXP __LDBL_MAX_EXP__
117+
118+
#define FLT_MAX_10_EXP __FLT_MAX_10_EXP__
119+
#define DBL_MAX_10_EXP __DBL_MAX_10_EXP__
120+
#define LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__
121+
122+
#define FLT_MAX __FLT_MAX__
123+
#define DBL_MAX __DBL_MAX__
124+
#define LDBL_MAX __LDBL_MAX__
125+
126+
#define FLT_EPSILON __FLT_EPSILON__
127+
#define DBL_EPSILON __DBL_EPSILON__
128+
#define LDBL_EPSILON __LDBL_EPSILON__
129+
130+
#define FLT_MIN __FLT_MIN__
131+
#define DBL_MIN __DBL_MIN__
132+
#define LDBL_MIN __LDBL_MIN__
133+
134+
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
135+
!defined(__STRICT_ANSI__) || \
136+
(defined(__cplusplus) && __cplusplus >= 201703L) || \
137+
(__STDC_HOSTED__ && defined(_AIX) && defined(_ALL_SOURCE))
138+
# define FLT_TRUE_MIN __FLT_DENORM_MIN__
139+
# define DBL_TRUE_MIN __DBL_DENORM_MIN__
140+
# define LDBL_TRUE_MIN __LDBL_DENORM_MIN__
141+
# define FLT_DECIMAL_DIG __FLT_DECIMAL_DIG__
142+
# define DBL_DECIMAL_DIG __DBL_DECIMAL_DIG__
143+
# define LDBL_DECIMAL_DIG __LDBL_DECIMAL_DIG__
144+
# define FLT_HAS_SUBNORM __FLT_HAS_DENORM__
145+
# define DBL_HAS_SUBNORM __DBL_HAS_DENORM__
146+
# define LDBL_HAS_SUBNORM __LDBL_HAS_DENORM__
147+
#endif
148+
149+
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || \
150+
!defined(__STRICT_ANSI__)
151+
/* C23 5.2.5.3.2p28 */
152+
# define FLT_SNAN (__builtin_nansf(""))
153+
# define DBL_SNAN (__builtin_nans(""))
154+
# define LDBL_SNAN (__builtin_nansl(""))
155+
156+
/* C23 5.2.5.3.3p32 */
157+
# define FLT_NORM_MAX __FLT_NORM_MAX__
158+
# define DBL_NORM_MAX __DBL_NORM_MAX__
159+
# define LDBL_NORM_MAX __LDBL_NORM_MAX__
160+
#endif
161+
162+
#ifdef __STDC_WANT_IEC_60559_TYPES_EXT__
163+
# define FLT16_MANT_DIG __FLT16_MANT_DIG__
164+
# define FLT16_DECIMAL_DIG __FLT16_DECIMAL_DIG__
165+
# define FLT16_DIG __FLT16_DIG__
166+
# define FLT16_MIN_EXP __FLT16_MIN_EXP__
167+
# define FLT16_MIN_10_EXP __FLT16_MIN_10_EXP__
168+
# define FLT16_MAX_EXP __FLT16_MAX_EXP__
169+
# define FLT16_MAX_10_EXP __FLT16_MAX_10_EXP__
170+
# define FLT16_MAX __FLT16_MAX__
171+
# define FLT16_EPSILON __FLT16_EPSILON__
172+
# define FLT16_MIN __FLT16_MIN__
173+
# define FLT16_TRUE_MIN __FLT16_TRUE_MIN__
174+
#endif /* __STDC_WANT_IEC_60559_TYPES_EXT__ */
175+
176+
#endif /* __CLANG_FLOAT_FLOAT_H */
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*===---- __float_header_macro.h -------------------------------------------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*/
9+
10+
#ifndef __CLANG_FLOAT_H
11+
#define __CLANG_FLOAT_H
12+
#endif /* __CLANG_FLOAT_H */
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*===---- __float_infinity_nan.h -------------------------------------------===
2+
*
3+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
* See https://llvm.org/LICENSE.txt for license information.
5+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
*
7+
*===-----------------------------------------------------------------------===
8+
*/
9+
10+
#ifndef __CLANG_FLOAT_INFINITY_NAN_H
11+
#define __CLANG_FLOAT_INFINITY_NAN_H
12+
13+
/* C23 5.2.5.3.3p29-30 */
14+
#undef INFINITY
15+
#undef NAN
16+
17+
#define INFINITY (__builtin_inff())
18+
#define NAN (__builtin_nanf(""))
19+
20+
#endif /* __CLANG_FLOAT_INFINITY_NAN_H */

0 commit comments

Comments
 (0)