Author: Aaron Ballman
Date: 2025-04-04T13:53:45-04:00
New Revision: b6b025797245a5e5416b522df041252e3c4ff868

URL: 
https://github.com/llvm/llvm-project/commit/b6b025797245a5e5416b522df041252e3c4ff868
DIFF: 
https://github.com/llvm/llvm-project/commit/b6b025797245a5e5416b522df041252e3c4ff868.diff

LOG: Fix the signature for __builtin___clear_cache (#134376)

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

Fixes #47833

Added: 
    clang/test/Sema/clear_cache.c

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/include/clang/Basic/Builtins.td

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c521b56a98606..77252e3a98235 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 c7ca607e4b3d2..2e077176ac7e9 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}}
+}
+


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to