https://gcc.gnu.org/g:e9180a7791b4035de3e92649e9bfdbd22d0406bc

commit r17-1818-ge9180a7791b4035de3e92649e9bfdbd22d0406bc
Author: Oleg Tolmatcev <[email protected]>
Date:   Wed Jun 24 19:35:47 2026 +0200

    i386: Make _m_prefetchw parameter const-qualified
    
    Match Clang's declaration of _m_prefetchw to avoid requiring
    const_cast<void *> at call sites.
    
    gcc/ChangeLog:
    
            * config/i386/prfchwintrin.h (_m_prefetchw): Take
            volatile const void * instead of void *.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/i386/prfchw-Wcast-qual-1.c: New test.
    
    Signed-off-by: oltolm <[email protected]>

Diff:
---
 gcc/config/i386/prfchwintrin.h                      |  4 ++--
 gcc/testsuite/gcc.target/i386/prfchw-Wcast-qual-1.c | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/gcc/config/i386/prfchwintrin.h b/gcc/config/i386/prfchwintrin.h
index af3bded18e06..2ac190964dec 100644
--- a/gcc/config/i386/prfchwintrin.h
+++ b/gcc/config/i386/prfchwintrin.h
@@ -29,9 +29,9 @@
 #define _PRFCHWINTRIN_H_INCLUDED
 
 extern __inline void __attribute__((__gnu_inline__, __always_inline__, 
__artificial__))
-_m_prefetchw (void *__P)
+_m_prefetchw (volatile const void *__P)
 {
-  __builtin_prefetch (__P, 1, 3 /* _MM_HINT_T0 */);
+  __builtin_prefetch ((const void *) __P, 1, 3 /* _MM_HINT_T0 */);
 }
 
 #endif /* _PRFCHWINTRIN_H_INCLUDED */
diff --git a/gcc/testsuite/gcc.target/i386/prfchw-Wcast-qual-1.c 
b/gcc/testsuite/gcc.target/i386/prfchw-Wcast-qual-1.c
new file mode 100644
index 000000000000..c6e86aa6d3d8
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/prfchw-Wcast-qual-1.c
@@ -0,0 +1,16 @@
+/* Verify that _m_prefetchw does not produce -Wcast-qual warnings when
+   included as a system header.  The cast (const void *) drops volatile
+   from volatile const void *, which would trigger -Wcast-qual if not
+   in a system header.  */
+/* { dg-do compile } */
+/* { dg-options "-mprfchw -O2 -Wcast-qual" } */
+
+#include <x86intrin.h>
+
+void
+prefetchw_cast_qual_test (volatile void *p)
+{
+    _m_prefetchw (p);
+}
+
+/* { dg-bogus "cast discards .volatile. qualifier" "" { target *-*-* } 0 } */

Reply via email to