From 2d71b6a001ae28881b5c3a0039312ac515a20e06 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Tue, 7 Jan 2025 11:01:06 -0800 Subject: [PATCH] [libc] Keep headers compatible with -std=c89 mode C89 doesn't have the `restrict` keyword. When in `-std=c89` mode, GNU-compatible compilers require the `__restrict` spelling. --- libc/include/__llvm-libc-common.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libc/include/__llvm-libc-common.h b/libc/include/__llvm-libc-common.h index d9d70aff771c0..c63eb134a5e5d 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