Skip to content

Commit bbf1900

Browse files
committed
[clang][Headers] Avoid compiler warnings in builtin headers
While debugging module support using -Wsystem-headers, we discovered that if -Werror, and -Wundef or -Wmacro-redefined are specified, they can cause errors to be generated in these builtin headers. Differential Revision: https://reviews.llvm.org/D130800
1 parent b5f76d8 commit bbf1900

File tree

9 files changed

+186
-59
lines changed

9 files changed

+186
-59
lines changed

clang/lib/Headers/float.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838
# undef FLT_MANT_DIG
3939
# undef DBL_MANT_DIG
4040
# undef LDBL_MANT_DIG
41-
# if __STDC_VERSION__ >= 199901L || !defined(__STRICT_ANSI__) || \
42-
__cplusplus >= 201103L || \
43-
(__STDC_HOSTED__ && defined(_AIX) && defined(_ALL_SOURCE))
41+
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
42+
!defined(__STRICT_ANSI__) || \
43+
(defined(__cplusplus) && __cplusplus >= 201103L) || \
44+
(__STDC_HOSTED__ && defined(_AIX) && defined(_ALL_SOURCE))
4445
# undef DECIMAL_DIG
4546
# endif
4647
# undef FLT_DIG
@@ -67,9 +68,10 @@
6768
# undef FLT_MIN
6869
# undef DBL_MIN
6970
# undef LDBL_MIN
70-
# if __STDC_VERSION__ >= 201112L || !defined(__STRICT_ANSI__) || \
71-
__cplusplus >= 201703L || \
72-
(__STDC_HOSTED__ && defined(_AIX) && defined(_ALL_SOURCE))
71+
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
72+
!defined(__STRICT_ANSI__) || \
73+
(defined(__cplusplus) && __cplusplus >= 201703L) || \
74+
(__STDC_HOSTED__ && defined(_AIX) && defined(_ALL_SOURCE))
7375
# undef FLT_TRUE_MIN
7476
# undef DBL_TRUE_MIN
7577
# undef LDBL_TRUE_MIN
@@ -92,8 +94,9 @@
9294
#define DBL_MANT_DIG __DBL_MANT_DIG__
9395
#define LDBL_MANT_DIG __LDBL_MANT_DIG__
9496

95-
#if __STDC_VERSION__ >= 199901L || !defined(__STRICT_ANSI__) || \
96-
__cplusplus >= 201103L || \
97+
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
98+
!defined(__STRICT_ANSI__) || \
99+
(defined(__cplusplus) && __cplusplus >= 201103L) || \
97100
(__STDC_HOSTED__ && defined(_AIX) && defined(_ALL_SOURCE))
98101
# define DECIMAL_DIG __DECIMAL_DIG__
99102
#endif
@@ -130,8 +133,9 @@
130133
#define DBL_MIN __DBL_MIN__
131134
#define LDBL_MIN __LDBL_MIN__
132135

133-
#if __STDC_VERSION__ >= 201112L || !defined(__STRICT_ANSI__) || \
134-
__cplusplus >= 201703L || \
136+
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
137+
!defined(__STRICT_ANSI__) || \
138+
(defined(__cplusplus) && __cplusplus >= 201703L) || \
135139
(__STDC_HOSTED__ && defined(_AIX) && defined(_ALL_SOURCE))
136140
# define FLT_TRUE_MIN __FLT_DENORM_MIN__
137141
# define DBL_TRUE_MIN __DBL_DENORM_MIN__

clang/lib/Headers/limits.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
/* C2x 5.2.4.2.1 */
6666
/* FIXME: This is using the placeholder dates Clang produces for these macros
6767
in C2x mode; switch to the correct values once they've been published. */
68-
#if __STDC_VERSION__ >= 202000L
68+
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000L
6969
#define BOOL_WIDTH __BOOL_WIDTH__
7070
#define CHAR_WIDTH CHAR_BIT
7171
#define SCHAR_WIDTH CHAR_BIT
@@ -93,7 +93,8 @@
9393
/* C99 5.2.4.2.1: Added long long.
9494
C++11 18.3.3.2: same contents as the Standard C Library header <limits.h>.
9595
*/
96-
#if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L
96+
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
97+
(defined(__cplusplus) && __cplusplus >= 201103L)
9798

9899
#undef LLONG_MIN
99100
#undef LLONG_MAX

clang/lib/Headers/stdarg.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ typedef __builtin_va_list va_list;
2323
*/
2424
#define __va_copy(d,s) __builtin_va_copy(d,s)
2525

26-
#if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L || !defined(__STRICT_ANSI__)
26+
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
27+
(defined(__cplusplus) && __cplusplus >= 201103L) || \
28+
!defined(__STRICT_ANSI__)
2729
#define va_copy(dest, src) __builtin_va_copy(dest, src)
2830
#endif
2931

clang/lib/Headers/stdatomic.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ extern "C" {
4545
/* 7.17.2 Initialization */
4646

4747
#define ATOMIC_VAR_INIT(value) (value)
48-
#if (__STDC_VERSION__ >= 201710L || __cplusplus >= 202002L) && \
48+
#if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L) || \
49+
(defined(__cplusplus) && __cplusplus >= 202002L)) && \
4950
!defined(_CLANG_DISABLE_CRT_DEPRECATION_WARNINGS)
5051
/* ATOMIC_VAR_INIT was deprecated in C17 and C++20. */
5152
#pragma clang deprecated(ATOMIC_VAR_INIT)

clang/lib/Headers/stdbool.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#define __bool_true_false_are_defined 1
1414

15-
#if __STDC_VERSION__ > 201710L
15+
#if defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L
1616
/* FIXME: We should be issuing a deprecation warning here, but cannot yet due
1717
* to system headers which include this header file unconditionally.
1818
*/
@@ -23,7 +23,7 @@
2323
#elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
2424
/* Define _Bool as a GNU extension. */
2525
#define _Bool bool
26-
#if __cplusplus < 201103L
26+
#if defined(__cplusplus) && __cplusplus < 201103L
2727
/* For C++98, define bool, false, true as a GNU extension. */
2828
#define bool bool
2929
#define false false

clang/lib/Headers/stddef.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ using ::std::nullptr_t;
9898
#endif /* defined(__need_NULL) */
9999

100100
#if defined(__need_STDDEF_H_misc)
101-
#if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L
101+
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
102+
(defined(__cplusplus) && __cplusplus >= 201103L)
102103
#include "__stddef_max_align_t.h"
103104
#endif
104105
#define offsetof(t, d) __builtin_offsetof(t, d)

0 commit comments

Comments
 (0)