[clang] Fix the signature for __builtin___clear_cache (PR #134376)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 4 06:07:20 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Aaron Ballman (AaronBallman)
<details>
<summary>Changes</summary>
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
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}}
+}
+
``````````
</details>
https://github.com/llvm/llvm-project/pull/134376
More information about the cfe-commits
mailing list