Skip to content

[libc] Define away __restrict in C++ without GNU extensions #114655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2024

Conversation

frobtech
Copy link
Contributor

@frobtech frobtech commented Nov 2, 2024

The C99 restrict keyword is spelled __restrict in the libc
headers so it can be parsed by C++ compilers with GNU extensions
that recognize it. When GNU extensions are not available in C++

The C99 restrict keyword is spelled __restrict in the libc
headers so it can be parsed by C++ compilers with GNU extensions
that recognize it.  When GNU extensions are not available in C++
@frobtech frobtech marked this pull request as ready for review November 2, 2024 09:34
@llvmbot llvmbot added the libc label Nov 2, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 2, 2024

@llvm/pr-subscribers-libc

Author: Roland McGrath (frobtech)

Changes

The C99 restrict keyword is spelled __restrict in the libc
headers so it can be parsed by C++ compilers with GNU extensions
that recognize it. When GNU extensions are not available in C++


Full diff: https://github.com/llvm/llvm-project/pull/114655.diff

1 Files Affected:

  • (modified) libc/include/__llvm-libc-common.h (+6)
diff --git a/libc/include/__llvm-libc-common.h b/libc/include/__llvm-libc-common.h
index 3af0b08e9e8668..e0e29bbbd5f87c 100644
--- a/libc/include/__llvm-libc-common.h
+++ b/libc/include/__llvm-libc-common.h
@@ -17,6 +17,12 @@
 #undef __END_C_DECLS
 #define __END_C_DECLS }
 
+// Standard C++ doesn't have C99 restrict but GNU C++ has it with __ spelling.
+#undef __restrict
+#ifndef __GNUC__
+#define __restrict
+#endif
+
 #undef _Noreturn
 #define _Noreturn [[noreturn]]
 

@frobtech frobtech merged commit 1c602c5 into llvm:main Nov 4, 2024
11 checks passed
@frobtech frobtech deleted the p/libc-restrict branch November 4, 2024 19:23
PhilippRados pushed a commit to PhilippRados/llvm-project that referenced this pull request Nov 6, 2024
)

The C99 restrict keyword is spelled __restrict in the libc
headers so it can be parsed by C++ compilers with GNU extensions
that recognize it.  When GNU extensions are not available in C++
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants