[libc-commits] [libc] ce33a48 - [libc] Keep headers compatible with -std=c89 mode (#121981)
via libc-commits
libc-commits at lists.llvm.org
Tue Jan 7 12:13:27 PST 2025
Author: Roland McGrath
Date: 2025-01-07T12:13:24-08:00
New Revision: ce33a48efdd61435e026733315f1ac960774c254
URL: https://github.com/llvm/llvm-project/commit/ce33a48efdd61435e026733315f1ac960774c254
DIFF: https://github.com/llvm/llvm-project/commit/ce33a48efdd61435e026733315f1ac960774c254.diff
LOG: [libc] Keep headers compatible with -std=c89 mode (#121981)
C89 doesn't have the `restrict` keyword. When in `-std=c89`
mode, GNU-compatible compilers require the `__restrict` spelling.
Added:
Modified:
libc/include/__llvm-libc-common.h
Removed:
################################################################################
diff --git a/libc/include/__llvm-libc-common.h b/libc/include/__llvm-libc-common.h
index d9d70aff771c08..c63eb134a5e5d7 100644
--- a/libc/include/__llvm-libc-common.h
+++ b/libc/include/__llvm-libc-common.h
@@ -50,7 +50,14 @@
#define __END_C_DECLS
#undef __restrict
-#define __restrict restrict // C99 and above support the restrict keyword.
+#if __STDC_VERSION__ >= 199901L
+// C99 and above support the restrict keyword.
+#define __restrict restrict
+#elif !defined(__GNUC__)
+// GNU-compatible compilers accept the __ spelling in all modes.
+// Otherwise, omit the qualifier for pure C89 compatibility.
+#define __restrict
+#endif
#undef _Noreturn
#if __STDC_VERSION__ >= 201112L
More information about the libc-commits
mailing list