[PATCH] D130800: [clang][Headers] Avoid compiler warnings in builtin headers

Dominic Chen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 29 14:38:21 PDT 2022


ddcc created this revision.
ddcc added reviewers: efriedma, rnk, aaron.ballman.
Herald added a project: All.
ddcc requested review of this revision.
Herald added a project: clang.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130800

Files:
  clang/lib/Headers/stddef.h
  clang/lib/Headers/stdint.h


Index: clang/lib/Headers/stdint.h
===================================================================
--- clang/lib/Headers/stdint.h
+++ clang/lib/Headers/stdint.h
@@ -91,6 +91,9 @@
  * defined if there exists an exact-width type of equal or greater width.
  */
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmacro-redefined"
+
 #ifdef __INT64_TYPE__
 # ifndef __int8_t_defined /* glibc sys/types.h also defines int64_t*/
 typedef __INT64_TYPE__ int64_t;
@@ -857,5 +860,7 @@
 #define WINT_WIDTH       __WINT_WIDTH__
 #endif
 
+#pragma GCC diagnostic pop
+
 #endif /* __STDC_HOSTED__ */
 #endif /* __CLANG_STDINT_H */
Index: clang/lib/Headers/stddef.h
===================================================================
--- clang/lib/Headers/stddef.h
+++ clang/lib/Headers/stddef.h
@@ -98,7 +98,8 @@
 #endif /* defined(__need_NULL) */
 
 #if defined(__need_STDDEF_H_misc)
-#if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) ||              \
+    (defined(__cplusplus) && __cplusplus >= 201103L)
 #include "__stddef_max_align_t.h"
 #endif
 #define offsetof(t, d) __builtin_offsetof(t, d)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130800.448717.patch
Type: text/x-patch
Size: 1177 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220729/98a7988c/attachment-0001.bin>


More information about the cfe-commits mailing list