https://github.com/vossjannik created 
https://github.com/llvm/llvm-project/pull/154946

The `_Interlocked*` and `_x*etbv` intrinsics are defined using the 
Microsoft-specific type __int64.

__int64 is defined as long long across all platforms.
However, in the builtin function database BuiltinsX86.td the intrinsics are 
defined using uint64_t.
The type uint64_t can be either long or long long, depending on the target 
platform.
This leads to incorrect definitions on platforms where uint64_t is not 
equivalent to long long.

This PR aligns the type definitions in BuiltinsX86.td with the function 
signatures in xsaveintrin.h and immintrin.h.

Following the precedent of functions like __emul(), we use the 
microsoft-specific unsigned __int64 definition in the header and use the 
resolved type 'unsigned long long int' in the builtin function database.

>From b57dad4eb7e948111736d06e5aff62946711c34f Mon Sep 17 00:00:00 2001
From: Jannik Voss <j.v...@beckhoff.com>
Date: Fri, 8 Aug 2025 09:53:54 +0200
Subject: [PATCH 1/2] Fix type definitions for _xgetbv and _xsetbv functions in
 BuiltinsX86

The _xgetbv and _xsetbv intrinsics are defined using __int64 in Intel's 
Intrinsics Guide and
Microsoft's x86 intrinsics list.

__int64 is defined as long long across all platforms.
However, in the builtin function database BuiltinsX86.td the intrinsics are 
defined using uint64_t.
The type uint64_t can be either long or long long, depending on the target 
platform. This
leads to incorrect definitions on platforms where uint64_t is not equivalent to 
long long.

This commit aligns the type definitions in BuiltinsX86.td with the function 
signatures in xsaveintrin.h.
Following the precedent of functions like __emul(),
we use the microsoft-specific unsigned __int64 definition in the header and use 
the resolved type
'unsigned long long int' in the builtin function database.
---
 clang/include/clang/Basic/BuiltinsX86.td | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/BuiltinsX86.td 
b/clang/include/clang/Basic/BuiltinsX86.td
index 67cbbfdec7aaf..63a78e6e6bf8e 100644
--- a/clang/include/clang/Basic/BuiltinsX86.td
+++ b/clang/include/clang/Basic/BuiltinsX86.td
@@ -768,7 +768,7 @@ let Features = "xsave", Attributes = [NoThrow] in {
 }
 
 let Header = "immintrin.h", Languages = "ALL_MS_LANGUAGES", Attributes = 
[NoThrow, RequireDeclaration] in {
-  def _xgetbv : X86LibBuiltin<"uint64_t(unsigned int)">;
+  def _xgetbv : X86LibBuiltin<"unsigned long long int(unsigned int)">;
 }
 
 let Features = "xsave", Attributes = [NoThrow] in {
@@ -776,7 +776,7 @@ let Features = "xsave", Attributes = [NoThrow] in {
 }
 
 let Header = "immintrin.h", Languages = "ALL_MS_LANGUAGES", Attributes = 
[NoThrow, RequireDeclaration] in {
-  def _xsetbv : X86LibBuiltin<"void(unsigned int, uint64_t)">;
+  def _xsetbv : X86LibBuiltin<"void(unsigned int, unsigned long long int)">;
 }
 
 let Features = "xsaveopt", Attributes = [NoThrow] in {

>From 816d0036e23a48dcd755b0c7ba18fe5f75cab5fa Mon Sep 17 00:00:00 2001
From: Jannik Voss <j.v...@beckhoff.com>
Date: Mon, 7 Jul 2025 21:49:22 +0200
Subject: [PATCH 2/2] Fix type definitions for _Interlocked* functions in
 BuiltinsX86

The WDK defines _InterlockedIncrement64 using LONGLONG, while LLVM's
intrin0.h uses __int64. Since __int64 is defined as long long across all
platforms, there is no mismatch between the WDK and LLVM's intrin0.h.

However, in the builtin function database BuiltinsX86.td,
_InterlockedIncrement64 is defined using int64_t. The type int64_t can
be either long or long long, depending on the target platform. This
leads to incorrect definitions on platforms where int64_t is not
equivalent to long long.

This commit aligns the type definitions in BuiltinsX86.td
with the function signatures in intrin0.h.
Following the precedent of functions like __emul(),
we use the microsoft-specifc __int64 definition in the header
and use the resolved type 'long long int' in the
builtin function database.

Affects: _InterlockedIncrement64, _InterlockedDecrement64,
_InterlockedExchange64, _InterlockedExchangeAdd64,
_InterlockedExchangeSub64, _InterlockedAnd64, _InterlockedOr64,
_InterlockedXor64
---
 clang/include/clang/Basic/BuiltinsX86.td | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/Basic/BuiltinsX86.td 
b/clang/include/clang/Basic/BuiltinsX86.td
index 63a78e6e6bf8e..ad8831ca13092 100644
--- a/clang/include/clang/Basic/BuiltinsX86.td
+++ b/clang/include/clang/Basic/BuiltinsX86.td
@@ -4769,14 +4769,14 @@ let Features = "sha512", Attributes = [NoThrow, 
RequiredVectorWidth<256>] in {
 }
 
 let Header = "intrin.h", Languages = "ALL_MS_LANGUAGES", Attributes = 
[NoThrow, RequireDeclaration] in {
-  def _InterlockedAnd64 : X86LibBuiltin<"int64_t(int64_t volatile *, 
int64_t)">;
-  def _InterlockedDecrement64 : X86LibBuiltin<"int64_t(int64_t volatile *)">;
-  def _InterlockedExchange64 : X86LibBuiltin<"int64_t(int64_t volatile *, 
int64_t)">;
-  def _InterlockedExchangeAdd64 : X86LibBuiltin<"int64_t(int64_t volatile *, 
int64_t)">;
-  def _InterlockedExchangeSub64 : X86LibBuiltin<"int64_t(int64_t volatile *, 
int64_t)">;
-  def _InterlockedIncrement64 : X86LibBuiltin<"int64_t(int64_t volatile *)">;
-  def _InterlockedOr64 : X86LibBuiltin<"int64_t(int64_t volatile *, int64_t)">;
-  def _InterlockedXor64 : X86LibBuiltin<"int64_t(int64_t volatile *, 
int64_t)">;
+  def _InterlockedAnd64 : X86LibBuiltin<"long long int(long long int volatile 
*, long long int)">;
+  def _InterlockedDecrement64 : X86LibBuiltin<"long long int(long long int 
volatile *)">;
+  def _InterlockedExchange64 : X86LibBuiltin<"long long int(long long int 
volatile *, long long int)">;
+  def _InterlockedExchangeAdd64 : X86LibBuiltin<"long long int(long long int 
volatile *, long long int)">;
+  def _InterlockedExchangeSub64 : X86LibBuiltin<"long long int(long long int 
volatile *, long long int)">;
+  def _InterlockedIncrement64 : X86LibBuiltin<"long long int(long long int 
volatile *)">;
+  def _InterlockedOr64 : X86LibBuiltin<"long long int(long long int volatile 
*, long long int)">;
+  def _InterlockedXor64 : X86LibBuiltin<"long long int(long long int volatile 
*, long long int)">;
 }
 
 let Features = "sm3", Attributes = [NoThrow, RequiredVectorWidth<128>] in {

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

Reply via email to