Skip to content

Commit 58c7880

Browse files
[stable/21.x][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. rdar://163129990
1 parent 3c09dcd commit 58c7880

File tree

11 files changed

+278
-162
lines changed

11 files changed

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