Skip to content

Fix the signature for __builtin___clear_cache #134376

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
Apr 4, 2025

Conversation

AaronBallman
Copy link
Collaborator

The signature was changed from void(char *, char *) to void(void *, void *) to match GCC's signature for the same builtin.

Fixes #47833

The signature was changed from void(char *, char *) to
void(void *, void *) to match GCC's signature for the same builtin.

Fixes llvm#47833
@AaronBallman AaronBallman added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" diverges-from:gcc Does the clang frontend diverge from gcc on this issue labels Apr 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 4, 2025

@llvm/pr-subscribers-clang

Author: Aaron Ballman (AaronBallman)

Changes

The signature was changed from void(char *, char *) to void(void *, void *) to match GCC's signature for the same builtin.

Fixes #47833


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

3 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+4)
  • (modified) clang/include/clang/Basic/Builtins.td (+1-1)
  • (added) clang/test/Sema/clear_cache.c (+12)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3055394dd8b6c..969bfb04623ed 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -354,6 +354,10 @@ Bug Fixes to Compiler Builtins
 
 - The behvaiour of ``__add_pointer`` and ``__remove_pointer`` for Objective-C++'s ``id`` and interfaces has been fixed.
 
+- The signature for ``__builtin___clear_cache`` was changed from
+  ``void(char *, char *)`` to ``void(void *, void *)`` to match GCC's signature
+  for the same builtin. (#GH47833)
+
 Bug Fixes to Attribute Support
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  - Fixed crash when a parameter to the ``clang::annotate`` attribute evaluates to ``void``. See #GH119125
diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td
index b2c7ddb43de55..868e5b92acdc9 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -920,7 +920,7 @@ def FrameAddress : Builtin {
 def ClearCache : Builtin {
   let Spellings = ["__builtin___clear_cache"];
   let Attributes = [NoThrow];
-  let Prototype = "void(char*, char*)";
+  let Prototype = "void(void*, void*)";
 }
 
 def BuiltinSetjmp : Builtin {
diff --git a/clang/test/Sema/clear_cache.c b/clang/test/Sema/clear_cache.c
new file mode 100644
index 0000000000000..e6a3421309967
--- /dev/null
+++ b/clang/test/Sema/clear_cache.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// Ensure that __builtin___clear_cache has the expected signature. Clang used
+// to have a signature accepting char * while GCC had a signature accepting
+// void * that was documented incorrectly.
+void test(void) {
+ int n = 0;
+  __builtin___clear_cache(&n, &n + 1); // Ok
+  
+  __builtin___clear_cache((const void *)&n, (const void *)(&n + 1)); // expected-warning 2 {{passing 'const void *' to parameter of type 'void *' discards qualifiers}}
+}
+

@AaronBallman AaronBallman merged commit b6b0257 into llvm:main Apr 4, 2025
16 checks passed
@AaronBallman AaronBallman deleted the aballman-gh47833 branch April 4, 2025 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category diverges-from:gcc Does the clang frontend diverge from gcc on this issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

__builtin___clear_cache() has a different prototype than GCC
3 participants