Skip to content

Commit 2f2b931

Browse files
committed
[C23] Correct the type for INFINITY and NAN in freestanding
This amends bcb7c38 to correct the type use for the two macros to be float rather than double. Also adds additional test coverage. #98018 was filed to track the duplicate diagnostic issue that was discovered.
1 parent 69192e0 commit 2f2b931

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

clang/lib/Headers/float.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@
164164
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || \
165165
!defined(__STRICT_ANSI__)
166166
/* C23 5.2.5.3.3p29-30 */
167-
# define INFINITY (__builtin_inf())
168-
# define NAN (__builtin_nan(""))
167+
# define INFINITY (__builtin_inff())
168+
# define NAN (__builtin_nanf(""))
169169
#endif
170170

171171
#ifdef __STDC_WANT_IEC_60559_TYPES_EXT__

clang/test/Headers/float.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
// RUN: %clang_cc1 -fsyntax-only -verify -std=c99 -ffreestanding %s
33
// RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -ffreestanding %s
44
// RUN: %clang_cc1 -fsyntax-only -verify -std=c23 -ffreestanding %s
5-
// RUN: %clang_cc1 -fsyntax-only -verify -std=c23 -ffreestanding -ffinite-math-only %s
5+
// RUN: %clang_cc1 -fsyntax-only -verify=finite -std=c23 -ffreestanding -ffinite-math-only %s
66
// RUN: %clang_cc1 -fsyntax-only -verify -xc++ -std=c++11 -ffreestanding %s
77
// RUN: %clang_cc1 -fsyntax-only -verify -xc++ -std=c++14 -ffreestanding %s
88
// RUN: %clang_cc1 -fsyntax-only -verify -xc++ -std=c++17 -ffreestanding %s
99
// RUN: %clang_cc1 -fsyntax-only -verify -xc++ -std=c++23 -ffreestanding %s
10+
// NOTE: C++23 wasn't based on top of C23, so it gets no diagnostics for
11+
// finite-math-only mode as happens in C. When C++ rebased onto C23, that
12+
// is when we'll issue diagnostics for INFINITY and NAN use.
1013
// RUN: %clang_cc1 -fsyntax-only -verify -xc++ -std=c++23 -ffreestanding -ffinite-math-only %s
1114
// expected-no-diagnostics
1215

@@ -218,6 +221,10 @@
218221
#ifndef NAN
219222
#error "Mandatory macro NAN is missing."
220223
#endif
224+
// FIXME: the NAN diagnostic should only be issued once, not twice.
225+
_Static_assert(_Generic(INFINITY, float : 1, default : 0), ""); // finite-warning {{use of infinity via a macro is undefined behavior due to the currently enabled floating-point options}}
226+
_Static_assert(_Generic(NAN, float : 1, default : 0), ""); // finite-warning {{use of NaN is undefined behavior due to the currently enabled floating-point options}} \
227+
finite-warning {{use of NaN via a macro is undefined behavior due to the currently enabled floating-point options}}
221228
#else
222229
#ifdef INFINITY
223230
#error "Macro INFINITY should not be defined."

0 commit comments

Comments
 (0)